{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-11-07T06:22:54.526526Z",
     "iopub.status.busy": "2023-11-07T06:22:54.526274Z",
     "iopub.status.idle": "2023-11-07T06:22:57.440795Z",
     "shell.execute_reply": "2023-11-07T06:22:57.440198Z",
     "shell.execute_reply.started": "2023-11-07T06:22:54.526495Z"
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "import seaborn as sns\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "import warnings\n",
    "import os\n",
    "import random\n",
    "from tqdm import tqdm\n",
    "\n",
    "import datetime\n",
    "\n",
    "import imp\n",
    "import utils\n",
    "imp.reload(utils)\n",
    "\n",
    "\n",
    "\n",
    "## 模型\n",
    "from sklearn.metrics import f1_score\n",
    "from sklearn.model_selection import StratifiedKFold\n",
    "import joblib\n",
    "import gc\n",
    "from sklearn.feature_extraction.text import TfidfVectorizer, CountVectorizer\n",
    "\n",
    "#from category_encoders.target_encoder import TargetEncoder\n",
    "from catboost import CatBoostClassifier\n",
    "from catboost import Pool\n",
    "\n",
    "import xgboost as xgb\n",
    "from sklearn.metrics import f1_score\n",
    "from sklearn.model_selection import StratifiedKFold\n",
    "from sklearn.metrics import roc_curve, auc,roc_auc_score\n",
    "\n",
    "import pickle\n",
    "\n",
    "\n",
    "from sklearn.metrics import classification_report,precision_score,recall_score,f1_score,precision_recall_curve\n",
    "from sklearn.metrics import roc_curve, auc"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-10-23T10:23:46.844226Z",
     "iopub.status.busy": "2023-10-23T10:23:46.843937Z",
     "iopub.status.idle": "2023-10-23T10:23:46.847101Z",
     "shell.execute_reply": "2023-10-23T10:23:46.846561Z",
     "shell.execute_reply.started": "2023-10-23T10:23:46.844195Z"
    }
   },
   "source": [
    "# 读取特征"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-11-07T06:22:57.442136Z",
     "iopub.status.busy": "2023-11-07T06:22:57.441923Z",
     "iopub.status.idle": "2023-11-07T06:23:18.950167Z",
     "shell.execute_reply": "2023-11-07T06:23:18.949475Z",
     "shell.execute_reply.started": "2023-11-07T06:22:57.442110Z"
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "TARGET_QZ_A = pd.read_csv('../contest/A/TARGET_QZ_A.csv')\n",
    "TARGET_QZ_train = pd.read_csv('../contest/train/TARGET_QZ.csv')\n",
    "\n",
    "TARGET_QZ = pd.concat([TARGET_QZ_train,TARGET_QZ_A],axis=0)\n",
    "\n",
    "\n",
    "# hjj特征\n",
    "with open('./feature/A_hjj_test.pkl', 'rb') as file:\n",
    "    hjj_test = pickle.load(file)\n",
    "    \n",
    "with open('./feature/A_hjj_train.pkl', 'rb') as file:\n",
    "    hjj_train = pickle.load(file)   \n",
    "    \n",
    "hjj_feature = pd.concat([hjj_train,hjj_test],axis = 0)\n",
    "    \n",
    "    \n",
    "# yxh特征\n",
    "# with open('../feature/yxh_6&&7_asset_1025_v2.pkl', 'rb') as file:\n",
    "#     yxh_67_asset = pickle.load(file)\n",
    "with open('./feature/A_9_nature.pkl', 'rb') as file:\n",
    "    yxh_9_nature = pickle.load(file)   \n",
    "with open('./feature/A_1_trnflw.pkl', 'rb') as file:\n",
    "    yxh_1_trnflw_1024 = pickle.load(file)  \n",
    "with open('./feature/A_2_QRYTRNFLW.pkl', 'rb') as file:\n",
    "    yxh_2_QRYTRNFLW_1024 = pickle.load(file)  \n",
    "with open('./feature/A_3_CSTLOG.pkl', 'rb') as file:\n",
    "    yxh_3_CSTLOG_1024 = pickle.load(file)  \n",
    "with open('./feature/A_4_CSTLOGQUERY.pkl', 'rb') as file:\n",
    "    yxh_4_CSTLOGQUERY_1024 = pickle.load(file)  \n",
    "with open('./feature/A_5_APS.pkl', 'rb') as file:\n",
    "    yxh_5_APS_1024 = pickle.load(file)  \n",
    "with open('./feature/A_6&&7_asset.pkl', 'rb') as file:\n",
    "    yxh_67_asset_1025_v2 = pickle.load(file)  \n",
    "with open('./feature/A_1234_hebing.pkl', 'rb') as file:\n",
    "    yxh_1234_hebing_1026 = pickle.load(file) \n",
    "    \n",
    "    \n",
    "## LYH特征\n",
    "with open('./feature/A_LYH_8_feature_PROD_feature_v1.pkl', 'rb') as file:\n",
    "    LYH_8_PROD_feature = pickle.load(file)\n",
    "with open('./feature/A_LYH_2_QRYTRNFLW_feature_v1.pkl', 'rb') as file:\n",
    "    LYH_2_QRYTRNFLW_feature = pickle.load(file)   \n",
    "with open('./feature/A_LYH_4_CSTLOGQUERY_feature_v1.pkl', 'rb') as file:\n",
    "    LYH_4_CSTLOGQUERY_feature = pickle.load(file)   \n",
    "with open('./feature/A_LYH_4_work_feature_v2.pkl', 'rb') as file:\n",
    "    LYH_4_work_feature_v2 = pickle.load(file)   \n",
    "with open('./feature/A_LYH_LR_feature.pkl', 'rb') as file:\n",
    "    LYH_LR_feature = pickle.load(file) \n",
    "    \n",
    "with open('./feature/A_other_1029.pkl', 'rb') as file:\n",
    "    other_group_1029 = pickle.load(file) \n",
    "    \n",
    "dataset =  TARGET_QZ.merge(hjj_feature, on = 'CUST_NO', how  = 'left')\n",
    "dataset =  dataset.merge(yxh_67_asset_1025_v2, on = 'CUST_NO', how  = 'left')   \n",
    "# dataset =  TARGET_QZ.merge(yxh_67_asset_1025_v2, on = 'CUST_NO', how  = 'left')   \n",
    "dataset =  dataset.merge(yxh_9_nature, on = 'CUST_NO', how  = 'left')  \n",
    "dataset =  dataset.merge(LYH_2_QRYTRNFLW_feature, on = 'CUST_NO', how  = 'left')  \n",
    "dataset =  dataset.merge(LYH_8_PROD_feature, on = 'CUST_NO', how  = 'left')  \n",
    "dataset =  dataset.merge(LYH_4_CSTLOGQUERY_feature, on = 'CUST_NO', how  = 'left')  \n",
    "dataset =  dataset.merge(LYH_4_work_feature_v2, on = 'CUST_NO', how  = 'left') \n",
    "dataset =  dataset.merge(LYH_LR_feature, on = 'CUST_NO', how  = 'left') \n",
    "dataset =  dataset.merge(yxh_1_trnflw_1024, on = 'CUST_NO', how  = 'left') \n",
    "dataset =  dataset.merge(yxh_2_QRYTRNFLW_1024, on = 'CUST_NO', how  = 'left') \n",
    "dataset =  dataset.merge(yxh_3_CSTLOG_1024, on = 'CUST_NO', how  = 'left') \n",
    "dataset =  dataset.merge(yxh_4_CSTLOGQUERY_1024, on = 'CUST_NO', how  = 'left') \n",
    "dataset =  dataset.merge(yxh_5_APS_1024, on = 'CUST_NO', how  = 'left') \n",
    "dataset =  dataset.merge(yxh_1234_hebing_1026, on = 'CUST_NO', how  = 'left') \n",
    "dataset =  dataset.merge(other_group_1029, on = 'CUST_NO', how  = 'left') \n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-11-07T06:23:18.952013Z",
     "iopub.status.busy": "2023-11-07T06:23:18.951787Z",
     "iopub.status.idle": "2023-11-07T06:23:18.991449Z",
     "shell.execute_reply": "2023-11-07T06:23:18.990802Z",
     "shell.execute_reply.started": "2023-11-07T06:23:18.951987Z"
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "feature_name = ['APSDCPTPRDNO_tfidf_0', 'APSDCPTPRDNO_tfidf_1','APSDCPTPRDNO_tfidf_2', 'APSDCPTPRDNO_tfidf_5','APSDCPTPRDNO_countvec_0', 'APSDTRCOD_tfidf_0','APSDTRCOD_tfidf_1', 'APSDTRCOD_tfidf_2', 'APSDTRCOD_tfidf_3','APSDTRCOD_tfidf_5', 'APSDTRCOD_tfidf_7', 'APSDTRCOD_countvec_2','APSDTRCOD_countvec_6', 'APSDTRCOD_countvec_7','APSDTRCHL_tfidf_1', 'APSDTRCHL_tfidf_5', 'APSDTRCHL_tfidf_6','APSDTRCHL_tfidf_9', 'APSDTRCHL_countvec_7','CARD_NO_APSDCPTPRDNO_w2v_3', 'CARD_NO_APSDTRCOD_w2v_5','CARD_NO_APSDTRCOD_w2v_6', 'CARD_NO_APSDTRCOD_w2v_7','CARD_NO_APSDTRCHL_w2v_4', 'APSDTRAMT_skew_aps_qz','APSDTRAMT_ABS_max_aps_qz', 'APSDTRAMT_ABS_min_aps_qz','APSDTRAMT_ABS_std_aps_qz', 'APSDTRAMT_ABS_sum_aps_qz','month_mean_aps_qz', 'month_skew_aps_qz', 'day_skew_aps_qz','hour_min_aps_qz', 'hour_median_aps_qz', 'daygap_max_aps_qz','daygap_std_aps_qz', 'daygap_skew_aps_qz','APSDTRAMT_mean_aps_qz_1488b47add3c27be40af16a79e78f465','APSDTRAMT_mean_aps_qz_3cc8c0101d1d765139bd9b79d2ba64b0','APSDTRAMT_mean_aps_qz_88851f9e0e9b482eacf54d9c91d3e01f','APSDTRAMT_max_aps_qz_1488b47add3c27be40af16a79e78f465','APSDTRAMT_max_aps_qz_27eecfaa93503c43a3adc94d5eada0cd','APSDTRAMT_max_aps_qz_bc8fdd95f635a41481952a34e6d474d3','APSDTRAMT_min_aps_qz_88851f9e0e9b482eacf54d9c91d3e01f','APSDTRAMT_median_aps_qz_b8a051d9371790c2f9085c364325d2e4','APSDTRAMT_std_aps_qz_1488b47add3c27be40af16a79e78f465','APSDTRAMT_std_aps_qz_3cc8c0101d1d765139bd9b79d2ba64b0','APSDTRAMT_std_aps_qz_50a111f66d3a4bf0b67fd5e1453a99e8','APSDTRAMT_skew_aps_qz_01fc06d5103d851bc6fa02dd1f1a3fe5','APSDTRAMT_skew_aps_qz_3c6c4e45e982dc80246b40db4bab70c3','APSDTRAMT_ptp_aps_qz_3c6c4e45e982dc80246b40db4bab70c3','APSDTRAMT_ptp_aps_qz_3cc8c0101d1d765139bd9b79d2ba64b0','APSDTRAMT_sum_aps_qz_01fc06d5103d851bc6fa02dd1f1a3fe5','APSDTRAMT_sum_aps_qz_3cc8c0101d1d765139bd9b79d2ba64b0','APSDTRAMT_sum_aps_qz_88851f9e0e9b482eacf54d9c91d3e01f','APSDTRAMT_ABS_max_aps_qz_88851f9e0e9b482eacf54d9c91d3e01f','APSDTRAMT_ABS_min_aps_qz_88851f9e0e9b482eacf54d9c91d3e01f','APSDTRAMT_ABS_median_aps_qz_50a111f66d3a4bf0b67fd5e1453a99e8','APSDTRAMT_ABS_median_aps_qz_bc8fdd95f635a41481952a34e6d474d3','APSDTRAMT_ABS_std_aps_qz_88851f9e0e9b482eacf54d9c91d3e01f','APSDTRAMT_ABS_skew_aps_qz_50a111f66d3a4bf0b67fd5e1453a99e8','APSDTRAMT_ABS_sum_aps_qz_01fc06d5103d851bc6fa02dd1f1a3fe5','APSDTRAMT_ABS_sum_aps_qz_88851f9e0e9b482eacf54d9c91d3e01f','month_mean_aps_qz_01fc06d5103d851bc6fa02dd1f1a3fe5','month_mean_aps_qz_3c6c4e45e982dc80246b40db4bab70c3','month_mean_aps_qz_3cc8c0101d1d765139bd9b79d2ba64b0','month_mean_aps_qz_88851f9e0e9b482eacf54d9c91d3e01f','month_min_aps_qz_88851f9e0e9b482eacf54d9c91d3e01f','month_min_aps_qz_bc8fdd95f635a41481952a34e6d474d3','month_std_aps_qz_3cc8c0101d1d765139bd9b79d2ba64b0','month_skew_aps_qz_3c6c4e45e982dc80246b40db4bab70c3','month_skew_aps_qz_3cc8c0101d1d765139bd9b79d2ba64b0','day_mean_aps_qz_27eecfaa93503c43a3adc94d5eada0cd','day_mean_aps_qz_b951c83181a042b34719459f94d78cbc','day_max_aps_qz_27eecfaa93503c43a3adc94d5eada0cd','day_max_aps_qz_88851f9e0e9b482eacf54d9c91d3e01f','day_min_aps_qz_01fc06d5103d851bc6fa02dd1f1a3fe5','day_min_aps_qz_b8a051d9371790c2f9085c364325d2e4','day_median_aps_qz_3cc8c0101d1d765139bd9b79d2ba64b0','day_std_aps_qz_3c6c4e45e982dc80246b40db4bab70c3','day_skew_aps_qz_01fc06d5103d851bc6fa02dd1f1a3fe5','day_skew_aps_qz_3c6c4e45e982dc80246b40db4bab70c3','day_skew_aps_qz_50a111f66d3a4bf0b67fd5e1453a99e8','hour_mean_aps_qz_3c6c4e45e982dc80246b40db4bab70c3','hour_min_aps_qz_01fc06d5103d851bc6fa02dd1f1a3fe5','hour_min_aps_qz_1488b47add3c27be40af16a79e78f465','hour_min_aps_qz_3c6c4e45e982dc80246b40db4bab70c3','hour_min_aps_qz_88851f9e0e9b482eacf54d9c91d3e01f','hour_median_aps_qz_01fc06d5103d851bc6fa02dd1f1a3fe5','hour_median_aps_qz_3c6c4e45e982dc80246b40db4bab70c3','hour_median_aps_qz_3cc8c0101d1d765139bd9b79d2ba64b0','hour_std_aps_qz_01fc06d5103d851bc6fa02dd1f1a3fe5','hour_std_aps_qz_88851f9e0e9b482eacf54d9c91d3e01f','hour_std_aps_qz_c29de004ad06129c243b586ca8dea80f','hour_skew_aps_qz_01fc06d5103d851bc6fa02dd1f1a3fe5','hour_skew_aps_qz_50a111f66d3a4bf0b67fd5e1453a99e8','hour_ptp_aps_qz_88851f9e0e9b482eacf54d9c91d3e01f','hour_ptp_aps_qz_b8a051d9371790c2f9085c364325d2e4','hour_sum_aps_qz_3c6c4e45e982dc80246b40db4bab70c3','hour_sum_aps_qz_88851f9e0e9b482eacf54d9c91d3e01f','minute_max_aps_qz_1488b47add3c27be40af16a79e78f465','minute_max_aps_qz_3c6c4e45e982dc80246b40db4bab70c3','minute_min_aps_qz_1488b47add3c27be40af16a79e78f465','minute_median_aps_qz_1488b47add3c27be40af16a79e78f465','minute_median_aps_qz_b951c83181a042b34719459f94d78cbc','minute_median_aps_qz_bc8fdd95f635a41481952a34e6d474d3','minute_std_aps_qz_01fc06d5103d851bc6fa02dd1f1a3fe5','minute_skew_aps_qz_50a111f66d3a4bf0b67fd5e1453a99e8','minute_ptp_aps_qz_3cc8c0101d1d765139bd9b79d2ba64b0','minute_sum_aps_qz_01fc06d5103d851bc6fa02dd1f1a3fe5','minute_sum_aps_qz_b951c83181a042b34719459f94d78cbc','dayofweek_mean_aps_qz_1488b47add3c27be40af16a79e78f465','dayofweek_mean_aps_qz_50a111f66d3a4bf0b67fd5e1453a99e8','dayofweek_mean_aps_qz_88851f9e0e9b482eacf54d9c91d3e01f','dayofweek_max_aps_qz_3c6c4e45e982dc80246b40db4bab70c3','dayofweek_median_aps_qz_3c6c4e45e982dc80246b40db4bab70c3','dayofweek_median_aps_qz_3cc8c0101d1d765139bd9b79d2ba64b0','dayofweek_std_aps_qz_3c6c4e45e982dc80246b40db4bab70c3','dayofweek_std_aps_qz_50a111f66d3a4bf0b67fd5e1453a99e8','dayofweek_std_aps_qz_88851f9e0e9b482eacf54d9c91d3e01f','dayofweek_skew_aps_qz_1488b47add3c27be40af16a79e78f465','dayofweek_skew_aps_qz_3c6c4e45e982dc80246b40db4bab70c3','dayofweek_skew_aps_qz_3cc8c0101d1d765139bd9b79d2ba64b0','dayofweek_ptp_aps_qz_01fc06d5103d851bc6fa02dd1f1a3fe5','dayofweek_sum_aps_qz_50a111f66d3a4bf0b67fd5e1453a99e8','daygap_mean_aps_qz_88851f9e0e9b482eacf54d9c91d3e01f','daygap_mean_aps_qz_c29de004ad06129c243b586ca8dea80f','daygap_max_aps_qz_3cc8c0101d1d765139bd9b79d2ba64b0','daygap_min_aps_qz_01fc06d5103d851bc6fa02dd1f1a3fe5','daygap_min_aps_qz_27eecfaa93503c43a3adc94d5eada0cd','daygap_min_aps_qz_3c6c4e45e982dc80246b40db4bab70c3','daygap_min_aps_qz_c29de004ad06129c243b586ca8dea80f','daygap_median_aps_qz_27eecfaa93503c43a3adc94d5eada0cd','daygap_median_aps_qz_bc8fdd95f635a41481952a34e6d474d3','daygap_median_aps_qz_c29de004ad06129c243b586ca8dea80f','daygap_skew_aps_qz_3c6c4e45e982dc80246b40db4bab70c3','daygap_ptp_aps_qz_3c6c4e45e982dc80246b40db4bab70c3','daygap_ptp_aps_qz_88851f9e0e9b482eacf54d9c91d3e01f','daygap_sum_aps_qz_3c6c4e45e982dc80246b40db4bab70c3','daygap_sum_aps_qz_bc8fdd95f635a41481952a34e6d474d3','APSDTRAMT_mean_aps_qz_0e30a5a85d29c720619212ed0721f096','APSDTRAMT_mean_aps_qz_c203106fbee9e0c716712d29be26b9eb','APSDTRAMT_max_aps_qz_8c9c388064b85b10604063ea2f015e7b','APSDTRAMT_min_aps_qz_01e0ba6a59386b8afd8f24849fb0cfa1','APSDTRAMT_min_aps_qz_8c9c388064b85b10604063ea2f015e7b','APSDTRAMT_min_aps_qz_c203106fbee9e0c716712d29be26b9eb','APSDTRAMT_ptp_aps_qz_0e30a5a85d29c720619212ed0721f096','APSDTRAMT_ptp_aps_qz_1d1fe13c960cff7c6f9dedeeb23a7524','APSDTRAMT_sum_aps_qz_1d1fe13c960cff7c6f9dedeeb23a7524','APSDTRAMT_sum_aps_qz_c203106fbee9e0c716712d29be26b9eb','APSDTRAMT_ABS_median_aps_qz_01e0ba6a59386b8afd8f24849fb0cfa1','APSDTRAMT_ABS_median_aps_qz_6d9345571f7032b7281da7f93d1ffb22','APSDTRAMT_ABS_sum_aps_qz_6d9345571f7032b7281da7f93d1ffb22','APSDTRAMT_ABS_sum_aps_qz_c203106fbee9e0c716712d29be26b9eb','month_mean_aps_qz_8c9c388064b85b10604063ea2f015e7b','month_mean_aps_qz_c203106fbee9e0c716712d29be26b9eb','month_min_aps_qz_8c9c388064b85b10604063ea2f015e7b','month_std_aps_qz_8c9c388064b85b10604063ea2f015e7b','month_skew_aps_qz_1d1fe13c960cff7c6f9dedeeb23a7524','day_mean_aps_qz_1d1fe13c960cff7c6f9dedeeb23a7524','day_min_aps_qz_01e0ba6a59386b8afd8f24849fb0cfa1','day_median_aps_qz_1d1fe13c960cff7c6f9dedeeb23a7524','day_median_aps_qz_8c9c388064b85b10604063ea2f015e7b','day_std_aps_qz_c203106fbee9e0c716712d29be26b9eb','day_skew_aps_qz_0e30a5a85d29c720619212ed0721f096','day_sum_aps_qz_6d9345571f7032b7281da7f93d1ffb22','hour_mean_aps_qz_1d1fe13c960cff7c6f9dedeeb23a7524','hour_min_aps_qz_1d1fe13c960cff7c6f9dedeeb23a7524','hour_median_aps_qz_1d1fe13c960cff7c6f9dedeeb23a7524','hour_std_aps_qz_0e30a5a85d29c720619212ed0721f096','hour_skew_aps_qz_c203106fbee9e0c716712d29be26b9eb','hour_ptp_aps_qz_55246355778cf140b52a5c9f30092cfd','hour_ptp_aps_qz_8c9c388064b85b10604063ea2f015e7b','hour_sum_aps_qz_8c9c388064b85b10604063ea2f015e7b','minute_mean_aps_qz_c203106fbee9e0c716712d29be26b9eb','minute_min_aps_qz_6d9345571f7032b7281da7f93d1ffb22','minute_std_aps_qz_1d1fe13c960cff7c6f9dedeeb23a7524','minute_sum_aps_qz_c203106fbee9e0c716712d29be26b9eb','dayofweek_mean_aps_qz_0e30a5a85d29c720619212ed0721f096','dayofweek_mean_aps_qz_c203106fbee9e0c716712d29be26b9eb','dayofweek_min_aps_qz_c203106fbee9e0c716712d29be26b9eb','dayofweek_median_aps_qz_0e30a5a85d29c720619212ed0721f096','dayofweek_std_aps_qz_0e30a5a85d29c720619212ed0721f096','dayofweek_std_aps_qz_c203106fbee9e0c716712d29be26b9eb','daygap_mean_aps_qz_1d1fe13c960cff7c6f9dedeeb23a7524','daygap_mean_aps_qz_c203106fbee9e0c716712d29be26b9eb','daygap_max_aps_qz_55246355778cf140b52a5c9f30092cfd','daygap_min_aps_qz_1d1fe13c960cff7c6f9dedeeb23a7524','daygap_min_aps_qz_6d9345571f7032b7281da7f93d1ffb22','daygap_min_aps_qz_c203106fbee9e0c716712d29be26b9eb','daygap_std_aps_qz_c203106fbee9e0c716712d29be26b9eb','APSDCPTPRDNO_nunique_aps_qz_01fc06d5103d851bc6fa02dd1f1a3fe5','APSDCPTPRDNO_nunique_aps_qz_3c6c4e45e982dc80246b40db4bab70c3','APSDCPTPRDNO_nunique_aps_qz_88851f9e0e9b482eacf54d9c91d3e01f','APSDCPTPRDNO_nunique_aps_qz_b8a051d9371790c2f9085c364325d2e4','APSDCPTPRDNO_nunique_aps_qz_c29de004ad06129c243b586ca8dea80f','APSDCPTPRDNO_nunique_aps_qz_0e30a5a85d29c720619212ed0721f096','APSDCPTPRDNO_nunique_aps_qz_8c9c388064b85b10604063ea2f015e7b','APSDTRCOD_per_27eecfaa93503c43a3adc94d5eada0cd','APSDTRCOD_per_3c6c4e45e982dc80246b40db4bab70c3','APSDTRCOD_per_b8a051d9371790c2f9085c364325d2e4','APSDTRCOD_per_c29de004ad06129c243b586ca8dea80f','APSDTRCHL_per_0e30a5a85d29c720619212ed0721f096','APSDTRCHL_per_8c9c388064b85b10604063ea2f015e7b', '特征值中心性','APSDTRCOD_count_6', 'aps_time_diff_max','CARD_NO_count_day_hour_std', 'CARD_NO_count_day_hour_std_4','CARD_NO_count_day_hour_sum_4','APSDTRAMT_sum_day_APSDTRAMT_in_mean','APSDTRAMT_sum_day_APSDTRAMT_out_skew','APSDTRAMT_sum_day_APSDTRAMT_median','APSDTRAMT_sum_day_APSDTRAMT_sum', 'APSDTRAMT_out/in_max','APSDTRAMT_out/in_median','APSDTRAMT_sum_day_APSDTRAMT_out_mean_6','APSDTRAMT_sum_day_APSDTRAMT_out_min_6','APSDTRAMT_sum_day_APSDTRAMT_out_skew_5','APSDTRAMT_sum_day_APSDTRAMT_mean_5','APSDTRAMT_sum_day_APSDTRAMT_std_4','APSDTRAMT_sum_day_APSDTRAMT_std_6','APSDTRAMT_sum_day_APSDTRAMT_skew_6', 'APSDTRAMT_out/in_max_4','APSDTRAMT_out/in_max_6', 'APSDTRAMT_out/in_min_6','APSDTRAMT_out/in_std_5', 'APSDTRAMT_out/in_skew_5','APSDTRAMT_out/in_skew_6', 'TFT_TRNAMT_median_mbank_trn','TFT_TRNAMT_sum_mbank_trn', 'month_mean_mbank_trn','day_min_mbank_trn', 'day_median_mbank_trn', 'hour_mean_mbank_trn','hour_max_mbank_trn', 'hour_skew_mbank_trn', 'hour_sum_mbank_trn','minute_skew_mbank_trn', 'minute_sum_mbank_trn','dayofweek_mean_mbank_trn', 'dayofweek_std_mbank_trn','daygap_mean_mbank_trn', 'daygap_max_mbank_trn','daygap_min_mbank_trn', 'daygap_std_mbank_trn','daygap_ptp_mbank_trn', 'daygap_sum_mbank_trn','TFT_STDBSNCOD_tfidf_1_x', 'TFT_STDBSNCOD_tfidf_2_x','TFT_STDBSNCOD_countvec_0_x', 'TFT_STDBSNCOD_countvec_3_x','TFT_STDBSNCOD_countvec_4_x', 'TFT_STDBSNCOD_countvec_8_x','TFT_TRNAMT_mean_mbank_trn_790437b5c04ac674519e99323691fcba','TFT_TRNAMT_max_mbank_trn_c5b1c177284d3a5fcb82a1421f7a4943','TFT_TRNAMT_min_mbank_trn_790437b5c04ac674519e99323691fcba','TFT_TRNAMT_median_mbank_trn_790437b5c04ac674519e99323691fcba','DAY_FA_BAL - MAVER_AUM_BAL', 'DAY_FA_BAL - YAVER_TOT_IVST_BAL','DAY_FA_BAL - MAVER_DPSA_BAL', 'DAY_FA_BAL / MAVER_DPSA_BAL','DAY_FA_BAL - SAVER_DPSA_BAL', 'DAY_FA_BAL / SAVER_DPSA_BAL','DAY_FA_BAL - YAVER_DPSA_BAL', 'DAY_FA_BAL - MAVER_TD_BAL','DAY_FA_BAL - SAVER_TD_BAL', 'MAVER_FA_BAL / DAY_AUM_BAL','MAVER_FA_BAL - MAVER_AUM_BAL', 'MAVER_FA_BAL / MAVER_AUM_BAL','MAVER_FA_BAL - SAVER_AUM_BAL', 'MAVER_FA_BAL / SAVER_AUM_BAL','MAVER_FA_BAL - SAVER_DPSA_BAL', 'MAVER_FA_BAL / MAVER_TD_BAL','SAVER_FA_BAL - SAVER_TOT_IVST_BAL', 'SAVER_FA_BAL / DPSA_BAL','SAVER_FA_BAL / YAVER_DPSA_BAL', 'YAVER_FA_BAL / MAVER_AUM_BAL','YAVER_FA_BAL / SAVER_DPSA_BAL', 'DAY_AUM_BAL - MAVER_DPSA_BAL','MAVER_AUM_BAL - SAVER_DPSA_BAL', 'MAVER_AUM_BAL - SAVER_TD_BAL','MAVER_AUM_BAL / SAVER_TD_BAL', 'MAVER_AUM_BAL - YAVER_TD_BAL','SAVER_AUM_BAL - MAVER_TOT_IVST_BAL', 'SAVER_AUM_BAL - DPSA_BAL','SAVER_AUM_BAL - MAVER_DPSA_BAL', 'SAVER_AUM_BAL / MAVER_DPSA_BAL','SAVER_AUM_BAL - SAVER_DPSA_BAL','YAVER_AUM_BAL - MAVER_TOT_IVST_BAL','YAVER_AUM_BAL / MAVER_TOT_IVST_BAL', 'YAVER_AUM_BAL - TD_BAL','YAVER_AUM_BAL / SAVER_TD_BAL','TOT_IVST_BAL - MAVER_TOT_IVST_BAL','TOT_IVST_BAL / SAVER_DPSA_BAL', 'TOT_IVST_BAL - YAVER_DPSA_BAL','MAVER_TOT_IVST_BAL - SAVER_DPSA_BAL','SAVER_TOT_IVST_BAL / DPSA_BAL', 'YAVER_TOT_IVST_BAL / DPSA_BAL','DPSA_BAL / MAVER_TD_BAL', 'MAVER_DPSA_BAL - YAVER_DPSA_BAL','MAVER_DPSA_BAL - YAVER_TD_BAL', 'SAVER_DPSA_BAL / YAVER_TD_BAL','MAVER_TD_BAL - YAVER_TD_BAL', 'SAVER_TD_BAL / YAVER_TD_BAL','DAY_FA_BAL', 'MAVER_FA_BAL', 'SAVER_FA_BAL', 'YAVER_FA_BAL','DAY_AUM_BAL', 'MAVER_AUM_BAL', 'SAVER_AUM_BAL', 'YAVER_AUM_BAL','DPSA_BAL', 'MAVER_DPSA_BAL', 'SAVER_DPSA_BAL', 'aum_y', 'aum_s','aum_m', 'DPSA_y', 'DPSA_s', 'DPSA_m', 'DAY_huoqi_aum','MAVER_huoqi_aum', 'SAVER_dingqi_aum', 'MAVER_huoding_aum','NTRL_CUST_SEX_CD', 'TFT_CSTNOQRYTRNFLWmonth_mean','TFT_CSTNOQRYTRNFLWmonth_std', 'TFT_CSTNOQRYTRNFLWmonth_median','TFT_CSTNOQRYTRNFLWmonth_skew', 'TFT_CSTNOQRYTRNFLWhour_min','TFT_CSTNOQRYTRNFLWhour_median', 'TFT_CSTNOQRYTRNFLWhour_skew','TFT_CSTNOQRYTRNFLWhour_nunique', 'TFT_CSTNOQRYTRNFLWsecond_skew','TFT_STDBSNCOD_tfidf_0_y', 'TFT_STDBSNCOD_tfidf_3_y','TFT_STDBSNCOD_tfidf_6_y', 'TFT_STDBSNCOD_countvec_4_y','TFT_STDBSNCOD_countvec_9_y', 'CLQ_CSTNOCSTLOGQUERYmonth_median','CLQ_CSTNOCSTLOGQUERYmonth_skew', 'CLQ_CSTNOCSTLOGQUERYhour_max','CLQ_CSTNOCSTLOGQUERYminute_mean', 'CLQ_BSNCOD_tfidf_1','CLQ_BSNCOD_tfidf_4', 'CLQ_BSNCOD_tfidf_5', 'APSDTRAMT_out_sum_7','APSDTRAMT_sum_rate_7', 'APSDTRAMT_in_count_14','APSDTRAMT_in_sum_21', 'APSDTRAMT_out_sum_21', 'APSDTRDAT_TM_H35','APSDTRAMT_in_sum_35', 'stranger_num13', 'aps_fast_out_amt_flag','DPFAPROD_SUM_LR', 'DPFAPROD_SUM_linear', 'TAGS_PROD_LR','TAGS_PROD_LR_linear', 'DP_CUST_LR', 'DP_CUST_LR_linear','CUST_FA_LR', 'CUST_FA_linear', 'trnflw_custno_time_diff_sum','trnflw_custno_time_diff_min', 'trnflw_custno_time_diff_skew','trnflw_custno_time_diff_std', 'trnflw_custno_time_diff_kurt','trnflw_mon_montimes_min', 'trnflw_mon_montimes_std','trnflw_day_TFT_DTE_day_sum', 'trnflw_day_TFT_DTE_day_median','trnflw_day_TFT_DTE_day_skew', 'trnflw_day_TFT_DTE_day_kurt','trnflw_day_daytimes_mean', 'trnflw_cnoAMT_TFT_TRNAMT_sum','trnflw_cnoAMT_TFT_TRNAMT_max', 'trnflw_cnoAMT_TFT_TRNAMT_min','trnflw_cnoAMT_TFT_TRNAMT_std', 'trnflw_mAMT_TFT_DTE_month_mean','trnflw_mAMT_TFT_DTE_month_max', 'trnflw_mAMT_TFT_DTE_month_std','trnflw_mAMT_TFT_TRNAMT_sum', 'trnflw_mAMT_TFT_TRNAMT_max','trnflw_dAMT_TFT_DTE_day_sum', 'trnflw_dAMT_TFT_DTE_day_std','trnflw_dAMT_TFT_TRNAMT_sum', 'trnflw_dAMT_TFT_TRNAMT_min','trnflw_dAMT_TFT_TRNAMT_std', 'trnflw_dcod_TFT_DTE_day_count','trnflw_dcod_TFT_DTE_day_nunique','trnflw_dcod_TFT_STDBSNCOD_count','trnflw_macc_TFT_DTE_month_nunique', 'times_std_trnflw_last14','time_diff_mean_trnflw_last14', 'time_diff_sum_trnflw_last14','time_diff_median_trnflw_last14', 'time_diff_max_trnflw_last14','time_diff_std_trnflw_last14', 'times_median_trnflw_last28','time_diff_mean_trnflw_last28', 'time_diff_sum_trnflw_last28','time_diff_std_trnflw_last28', 'time_diff_mean_trnflw_last42','time_diff_median_trnflw_last42', 'time_diff_std_trnflw_last42','time_diff_mean_trnflw_last56', 'time_diff_sum_trnflw_last56','time_diff_std_trnflw_last56', 'time_diff_trnflw_rate_last14','times_trnflw_rate_last56', 'TFT_TRNAMT_mean_trnflwam_last28','TFT_TRNAMT_min_trnflwam_last28', 'TFT_TRNAMT_dr_min_last28','TFT_TRNAMT_dr_mean_last56', 'QRYTRNFLW_times_mean','QRYTRNFLW_times_max', 'QRYTRNFLW_times_std','QRYTRNFLW_time_diff_sum', 'QRYTRNFLW_time_diff_median','QRYTRNFLW_time_diff_min', 'QRYTRNFLW_time_diff_std','QRYTRNFLW_m_TFT_DTE_month_median', 'QRYTRNFLW_m_montimes_skew','QRYTRNFLW_d_TFT_DTE_day_min', 'QRYTRNFLW_d_TFT_DTE_day_skew','QRYTRNFLW_d_daytimes_mean', 'QRYTRNFLW_d_daytimes_max','QRYTRNFLW_d_daytimes_min', 'QRYTRNFLW_d_daytimes_std','QRYTRNFLW_cod_TFT_STDBSNCOD_nunique','QRYTRNFLW_mcod_TFT_STDBSNCOD_nunique','QRYTRNFLW_dcod_TFT_STDBSNCOD_nunique','times_sum_QRYTRNFLW_last14', 'times_median_QRYTRNFLW_last14','time_diff_mean_QRYTRNFLW_last14','time_diff_max_QRYTRNFLW_last14', 'time_diff_std_QRYTRNFLW_last14','time_diff_kurt_QRYTRNFLW_last14', 'times_max_QRYTRNFLW_last28','times_std_QRYTRNFLW_last28', 'time_diff_median_QRYTRNFLW_last28','time_diff_max_QRYTRNFLW_last28', 'time_diff_std_QRYTRNFLW_last28','times_mean_QRYTRNFLW_last42', 'times_std_QRYTRNFLW_last42','time_diff_median_QRYTRNFLW_last42','times_median_QRYTRNFLW_last56', 'times_std_QRYTRNFLW_last56','time_diff_median_QRYTRNFLW_last56','time_diff_skew_QRYTRNFLW_last56','time_diff_std_QRYTRNFLW_last56','time_QRYTRNFLW_diff_rate_last14', 'CSTLOGQUERY_times_mean','CSTLOGQUERY_times_sum', 'CSTLOGQUERY_time_diff_median','CSTLOGQUERY_time_diff_min', 'CSTLOGQUERY_m_CLQ_DTE_month_mean','CSTLOGQUERY_m_montimes_min', 'CSTLOGQUERY_cod_CLQ_BSNCOD_nunique','CSTLOGQUERY_dcod_CLQ_BSNCOD_nunique','time_diff_mean_CSTLOGQUERY_last28','time_diff_median_CSTLOGQUERY_last28','time_diff_mean_CSTLOGQUERY_last42','time_diff_mean_CSTLOGQUERY_last56', 'APS_time_diff_median','APS_time_diff_min', 'APS_time_diff_std','APS_d_APSDTRDAT_TM_day_skew', 'APS_d_APSDTRDAT_TM_day_std','APS_d_APSDTRDAT_TM_day_kurt', 'APS_d_daytimes_std','APS_outamt_APSDTRAMT_sum', 'APS_outamt_APSDTRAMT_std','APS_moutamt_APSDTRDAT_TM_month_mean','APS_moutamt_APSDTRAMT_skew', 'APS_moutamt_APSDTRAMT_std','APS_doutamt_APSDTRDAT_TM_day_sum','APS_doutamt_APSDTRDAT_TM_day_min','APS_doutamt_APSDTRDAT_TM_day_skew', 'APS_doutamt_APSDTRAMT_std','APS_inmamt_APSDTRDAT_TM_month_sum','APS_inmamt_APSDTRDAT_TM_month_max', 'APS_inmamt_APSDTRAMT_mean','APS_inmamt_APSDTRAMT_min', 'APS_indamt_APSDTRDAT_TM_day_mean','APS_indamt_APSDTRDAT_TM_day_std', 'time_diff_median_APS_last14','times_mean_APS_last28', 'times_median_APS_last28','time_diff_mean_APS_last28', 'time_diff_kurt_APS_last28','time_diff_median_APS_last42', 'time_diff_mean_APS_last56','time_diff_skew_APS_last56', 'time_diff_kurt_APS_last56','APSDTRAMT_sum_APSout_last28', 'APSDTRAMT_min_APSout_last56','out_APSDTRAMT_dr_mean_last28', 'out_APSDTRAMT_dr_max_last42','APSDTRAMT_min_APSin_last28', 'APSDTRAMT_mean_APSin_last42','APSDTRAMT_min_APSin_last42', 'APSDTRAMT_mean_APSin_last56','in_APSDTRAMT_dr_mean_last28', 'in_APSDTRAMT_dr_mean_last42','in_APSDTRAMT_dr_max_last42','TFT_TRNAMT_min_mbank_trn_mamt_6_790437b5c04ac674519e99323691fcba','TFT_TRNAMT_median_mbank_trn_mamt_6_790437b5c04ac674519e99323691fcba','TFT_TRNAMT_std_mbank_trn_mamt_4_790437b5c04ac674519e99323691fcba','TFT_TRNAMT_std_mbank_trn_mamt_6_790437b5c04ac674519e99323691fcba','TFT_TRNAMT_sum_mbank_trn_mamt_6_790437b5c04ac674519e99323691fcba','TFT_TRNAMT_count_mbank_trn_mamt_6_790437b5c04ac674519e99323691fcba','TFT_TRNAMT_max_mbank_trn_wamt_1_790437b5c04ac674519e99323691fcba','TFT_TRNAMT_max_mbank_trn_wamt_6_790437b5c04ac674519e99323691fcba','TFT_TRNAMT_std_mbank_trn_wamt_2_790437b5c04ac674519e99323691fcba','TFT_TRNAMT_std_mbank_trn_wamt_3_790437b5c04ac674519e99323691fcba','TFT_CSTACC_count_mbank_trn_mcnt_6_790437b5c04ac674519e99323691fcba','TFT_CRPACC_nunique_mbank_trn_yacccnt_c5b1c177284d3a5fcb82a1421f7a4943_x','TFT_CRPACC_nunique_mbank_trn_yacccnt_790437b5c04ac674519e99323691fcba_y','TFT_CRPACC_nunique_mbank_trn_macccnt_6_790437b5c04ac674519e99323691fcba','TFT_CRPACC_count_mbank_trn_macccnt_6_790437b5c04ac674519e99323691fcba','TFT_CRPACC_nunique_mbank_trn_wacccnt_3_790437b5c04ac674519e99323691fcba','TFT_CRPACC_nunique_mbank_trn_wacccnt_6_790437b5c04ac674519e99323691fcba','TFT_CRPACC_count_mbank_trn_wacccnt_2_790437b5c04ac674519e99323691fcba','CUST_NO_count_mbank_qry_ycnt_db0a93901176d46183168b40ff174b52','CUST_NO_count_mbank_qry_mcnt_4_4a50500443ba4972159b20abae2eb1d8','CUST_NO_count_mbank_qry_mcnt_6_4a50500443ba4972159b20abae2eb1d8','CUST_NO_count_mbank_qry_mcnt_6_6f6af3fc3864671b3ccbf2093ecfc8ba','CUST_NO_count_mbank_qry_mcnt_6_db0a93901176d46183168b40ff174b52','CUST_NO_count_mbank_qry_wcnt_0_4a50500443ba4972159b20abae2eb1d8','CUST_NO_count_mbank_qry_wcnt_1_4a50500443ba4972159b20abae2eb1d8','CUST_NO_count_mbank_qry_wcnt_1_db0a93901176d46183168b40ff174b52','CUST_NO_count_mbank_qry_wcnt_2_4a50500443ba4972159b20abae2eb1d8','CUST_NO_count_mbank_qry_wcnt_3_e481bae2b43d054e6afb6d6bf8760169','CUST_NO_count_mbank_qry_wcnt_4_db0a93901176d46183168b40ff174b52','CUST_NO_count_mbank_qry_wcnt_5_4a50500443ba4972159b20abae2eb1d8','CUST_NO_count_mbank_qry_wcnt_5_6f6af3fc3864671b3ccbf2093ecfc8ba','max_amt_days_to_now_0_in', 'max_amt_days_to_now_1_in','APSDPRDNO_date_months_to_now_APSDTRAMT_max_0_in','APSDPRDNO_date_months_to_now_APSDTRAMT_min_1_in','APSDPRDNO_date_months_to_now_APSDTRAMT_median_0_in','APSDPRDNO_date_months_to_now_APSDTRAMT_skew_1_in','APSDPRDNO_date_weeks_to_now_APSDTRAMT_min_5_in','APSDPRDNO_date_weeks_to_now_APSDTRAMT_sum_0_in','APSDPRDNO_date_weeks_to_now_APSDTRAMT_sum_5_in','APSDPRDNO_date_weeks_to_now_APSDTRAMT_skew_2_in','APSDPRDNO_date_weeks_to_now_APSDTRAMT_skew_6_in','APSDPRDNO_date_weeks_to_now_APSDTRAMT_skew_7_in','APSDPRDNO_date_weeks_to_now_APSDTRAMT_kurt_1_in','APSDPRDNO_date_weeks_to_now_APSDTRAMT_kurt_2_in','APSDPRDNO_date_weeks_to_now_APSDTRAMT_kurt_6_in','APSDPRDNO_date_weeks_to_now_count_sum_0_in','APSDPRDNO_date_weeks_to_now_count_sum_1_in','APSDPRDNO_date_weeks_to_now_count_sum_7_in','APSDPRDNO_date_weeks_to_now_APSDTRCOD_nunique_8_in','APSDPRDNO_APSDTRCHL_APSDTRAMT_mean_e0457a5f5527aa8db06ede414933fecd_in','APSDPRDNO_APSDTRCHL_APSDTRAMT_min_1d1fe13c960cff7c6f9dedeeb23a7524_in','APSDPRDNO_APSDTRCHL_APSDTRAMT_median_1d1fe13c960cff7c6f9dedeeb23a7524_in','APSDPRDNO_APSDTRCHL_APSDTRAMT_std_c203106fbee9e0c716712d29be26b9eb_in','APSDPRDNO_APSDTRCHL_APSDTRAMT_skew_c203106fbee9e0c716712d29be26b9eb_in','APSDPRDNO_APSDTRCHL_APSDTRAMT_skew_e0457a5f5527aa8db06ede414933fecd_in','APSDPRDNO_APSDTRCHL_APSDTRAMT_kurt_0e30a5a85d29c720619212ed0721f096_in','APSDPRDNO_APSDTRCHL_APSDTRAMT_kurt_c203106fbee9e0c716712d29be26b9eb_in','APSDPRDNO_APSDTRCHL_APSDPRDNO_count_833c893caec34ea7a6ad91fc874504e1_in','APSDPRDNO_APSDTRCHL_APSDPRDNO_count_a155a6e28386a7c6ed15bba31bf0fefd_in','APSDPRDNO_APSDTRCHL_APSDPRDNO_count_f1011e59bf940b1141498087caf466d6_in','APSDPRDNO_APSDTRCHL_APSDPRDNO_count_1d76f172031f7709a83572bf596c1382_div_tr_freq_in','APSDPRDNO_APSDTRCHL_APSDPRDNO_count_833c893caec34ea7a6ad91fc874504e1_div_tr_freq_in','APSDPRDNO_APSDTRCHL_APSDPRDNO_count_e0457a5f5527aa8db06ede414933fecd_div_tr_freq_in','recent_days_to_now_0_out','APSDPRDNO_date_months_to_now_APSDTRAMT_max_0_out','APSDPRDNO_date_months_to_now_APSDTRAMT_sum_0_out','APSDPRDNO_date_months_to_now_APSDTRCOD_nunique_0_out','APSDPRDNO_date_weeks_to_now_APSDTRAMT_mean_0_out','APSDPRDNO_date_weeks_to_now_APSDTRAMT_mean_3_out','APSDPRDNO_date_weeks_to_now_APSDTRAMT_max_5_out','APSDPRDNO_date_weeks_to_now_APSDTRAMT_max_6_out','APSDPRDNO_date_weeks_to_now_APSDTRAMT_min_3_out','APSDPRDNO_date_weeks_to_now_APSDTRAMT_min_8_out','APSDPRDNO_date_weeks_to_now_APSDTRAMT_median_0_out','APSDPRDNO_date_weeks_to_now_APSDTRAMT_median_3_out','APSDPRDNO_date_weeks_to_now_APSDTRAMT_median_7_out','APSDPRDNO_date_weeks_to_now_APSDTRAMT_median_8_out','APSDPRDNO_date_weeks_to_now_APSDTRAMT_sum_3_out','APSDPRDNO_date_weeks_to_now_APSDTRAMT_sum_4_out','APSDPRDNO_date_weeks_to_now_APSDTRAMT_sum_6_out','APSDPRDNO_date_weeks_to_now_APSDTRAMT_skew_8_out','APSDPRDNO_date_weeks_to_now_APSDTRAMT_kurt_0_out','APSDPRDNO_date_weeks_to_now_APSDTRAMT_kurt_5_out','APSDPRDNO_date_weeks_to_now_APSDTRAMT_kurt_8_out','APSDPRDNO_APSDTRCHL_APSDTRAMT_mean_e0457a5f5527aa8db06ede414933fecd_out','APSDPRDNO_APSDTRCHL_APSDTRAMT_max_0e30a5a85d29c720619212ed0721f096_out','APSDPRDNO_APSDTRCHL_APSDTRAMT_max_e0457a5f5527aa8db06ede414933fecd_out','APSDPRDNO_APSDTRCHL_APSDTRAMT_median_c203106fbee9e0c716712d29be26b9eb_out','APSDPRDNO_APSDTRCHL_APSDTRAMT_median_e0457a5f5527aa8db06ede414933fecd_out','APSDPRDNO_APSDTRCHL_APSDTRAMT_std_0e30a5a85d29c720619212ed0721f096_out','APSDPRDNO_APSDTRCHL_APSDTRAMT_std_e0457a5f5527aa8db06ede414933fecd_out','APSDPRDNO_APSDTRCHL_APSDTRAMT_sum_e0457a5f5527aa8db06ede414933fecd_out','APSDPRDNO_APSDTRCHL_APSDTRAMT_skew_e0457a5f5527aa8db06ede414933fecd_out','APSDPRDNO_APSDTRCHL_APSDPRDNO_count_833c893caec34ea7a6ad91fc874504e1_out','APSDPRDNO_APSDTRCHL_APSDPRDNO_count_d42ebe89d9717253a6bcdce3f18e86cb_out','APSDPRDNO_APSDTRCHL_APSDPRDNO_count_f1011e59bf940b1141498087caf466d6_out','APSDPRDNO_APSDTRCHL_APSDPRDNO_count_099d3274540524610cf81334bee22a30_div_tr_freq_out','APSDPRDNO_APSDTRCHL_APSDPRDNO_count_8c9c388064b85b10604063ea2f015e7b_div_tr_freq_out','APSDPRDNO_APSDTRCHL_APSDPRDNO_count_be07ad362a6c06779291a5ceb3c581d3_div_tr_freq_out','APSDPRDNO_APSDTRCHL_APSDPRDNO_count_f1011e59bf940b1141498087caf466d6_div_tr_freq_out','recent_days_to_now_0_net','APSDPRDNO_date_months_to_now_APSDTRAMT_mean_0_net','APSDPRDNO_date_months_to_now_APSDTRAMT_max_0_net','APSDPRDNO_date_months_to_now_APSDTRAMT_max_1_net','APSDPRDNO_date_months_to_now_APSDTRAMT_std_0_net','APSDPRDNO_date_months_to_now_APSDTRAMT_std_1_net','APSDPRDNO_date_weeks_to_now_APSDTRAMT_max_1_net','APSDPRDNO_date_weeks_to_now_APSDTRAMT_max_2_net','APSDPRDNO_date_weeks_to_now_APSDTRAMT_max_6_net','APSDPRDNO_date_weeks_to_now_APSDTRAMT_median_5_net','APSDPRDNO_date_weeks_to_now_APSDTRAMT_std_7_net','APSDPRDNO_date_weeks_to_now_APSDTRAMT_sum_4_net','APSDPRDNO_date_weeks_to_now_APSDTRAMT_skew_4_net','APSDPRDNO_date_weeks_to_now_APSDTRAMT_skew_5_net','APSDPRDNO_date_weeks_to_now_APSDTRAMT_skew_6_net','APSDPRDNO_date_weeks_to_now_APSDTRAMT_skew_7_net','APSDPRDNO_date_weeks_to_now_APSDTRAMT_skew_8_net','APSDPRDNO_date_weeks_to_now_APSDTRAMT_kurt_2_net','APSDPRDNO_date_weeks_to_now_APSDTRAMT_kurt_6_net','aps_APSDPRDNO_date_months_to_now_strange_amts_mean_0','aps_APSDPRDNO_date_months_to_now_strange_cpts_mean_0','aps_APSDPRDNO_date_months_to_now_strange_cpts_max_0','aps_APSDPRDNO_date_months_to_now_strange_cpts_min_0','aps_APSDPRDNO_date_months_to_now_strange_cpts_std_0','aps_APSDPRDNO_date_months_to_now_strange_cpts_sum_0','aps_APSDPRDNO_date_months_to_now_strange_cpts_kurt_0','aps_APSDPRDNO_date_months_to_now_count_strange_min_0','aps_APSDPRDNO_date_months_to_now_count_strange_sum_0','aps_APSDPRDNO_date_months_to_now_count_strange_kurt_0','aps_APSDPRDNO_date_weeks_to_now_strange_amts_mean_1','aps_APSDPRDNO_date_weeks_to_now_strange_amts_max_2','aps_APSDPRDNO_date_weeks_to_now_strange_amts_min_0','aps_APSDPRDNO_date_weeks_to_now_strange_amts_min_3','aps_APSDPRDNO_date_weeks_to_now_strange_amts_sum_0','aps_APSDPRDNO_date_weeks_to_now_strange_cpts_mean_0','aps_APSDPRDNO_date_weeks_to_now_strange_cpts_mean_3','aps_APSDPRDNO_date_weeks_to_now_strange_cpts_max_0','aps_APSDPRDNO_date_weeks_to_now_strange_cpts_max_3','aps_APSDPRDNO_date_weeks_to_now_strange_cpts_min_0','aps_APSDPRDNO_date_weeks_to_now_strange_cpts_min_1','aps_APSDPRDNO_date_weeks_to_now_strange_cpts_min_4','aps_APSDPRDNO_date_weeks_to_now_strange_cpts_median_1','aps_APSDPRDNO_date_weeks_to_now_strange_cpts_sum_0','aps_APSDPRDNO_date_weeks_to_now_strange_cpts_sum_1','aps_APSDPRDNO_date_weeks_to_now_count_strange_mean_0','aps_APSDPRDNO_date_weeks_to_now_count_strange_mean_1','aps_APSDPRDNO_date_weeks_to_now_count_strange_mean_3','aps_APSDPRDNO_date_weeks_to_now_count_strange_max_0','aps_APSDPRDNO_date_weeks_to_now_count_strange_sum_0','aps_APSDPRDNO_date_weeks_to_now_count_strange_sum_3','aps_APSDPRDNO_APSDTRCHL_strange_amts_mean_c203106fbee9e0c716712d29be26b9eb','aps_APSDPRDNO_APSDTRCHL_strange_amts_mean_e0457a5f5527aa8db06ede414933fecd','aps_APSDPRDNO_APSDTRCHL_strange_amts_max_0e30a5a85d29c720619212ed0721f096','aps_APSDPRDNO_APSDTRCHL_strange_amts_max_e0457a5f5527aa8db06ede414933fecd','aps_APSDPRDNO_APSDTRCHL_strange_amts_min_e0457a5f5527aa8db06ede414933fecd','aps_APSDPRDNO_APSDTRCHL_strange_amts_median_e0457a5f5527aa8db06ede414933fecd','aps_APSDPRDNO_APSDTRCHL_strange_amts_std_e0457a5f5527aa8db06ede414933fecd','aps_APSDPRDNO_APSDTRCHL_strange_amts_sum_e0457a5f5527aa8db06ede414933fecd','APSDPRDNO_APSDTRCHL_APSDPRDNO_count_833c893caec34ea7a6ad91fc874504e1_empty','aps_data0414_0515nunique', 'aps_data0515_0615nunique','aps_data0414_0515sum', 'aps_money_S0_data0414_0515sum','aps_money_S0_data0515_0615sum','aps_qz_APSDTRCOD_two_data0515_0615count','mbank_trnflw_TFT_TRNAMT_data0515_0615sum','mbank_trnflw_TFT_CRPACC_data0414_0515nunique','mbank_qrytrnflw_TFT_STDBSNCOD_max_data0414_0515count','mbank_qrytrnflw_TFT_STDBSNCOD_max_data0515_0615count','mbank_qrytrnflw_TFT_STDBSNCOD_two_data0414_0515count','mbank_qrytrnflw_TFT_STDBSNCOD_two_data0515_0615count','aps_data0428_0505nunique', 'aps_data0505_0512nunique','aps_APSDTRCOD_data0414_0421nunique','aps_qz_APSDTRCOD_max_data0428_0505count','aps_qz_APSDTRCOD_max_data0505_0512count','aps_qz_APSDTRCOD_max_data0519_0526count','aps_qz_APSDTRCOD_two_data0602_0609count','aps_qz_APSDTRCHL_max_data0421_0428count','mbank_trnflw_TFT_STDBSNCOD_data0602_0609nunique','mbank_trnflw_TFT_TRNAMT_data0602_0609sum','mbank_trnflw_TFT_CRPACC_data0602_0609nunique','mbank_qrytrnflw_TFT_STDBSNCOD_data0414_0421nunique','mbank_qrytrnflw_TFT_STDBSNCOD_data0428_0505nunique','mbank_qrytrnflw_TFT_STDBSNCOD_max_data0512_0519count','mbank_qrytrnflw_TFT_STDBSNCOD_two_data0428_0505count','mbank_qrytrnflw_TFT_STDBSNCOD_three_data0512_0519count','aps_night_00_06_data0414_0515nunique','aps_night_00_06_data0515_0615nunique','aps_money_B0_night_00_06_data0414_0515sum','aps_money_S0_night_00_06_data0414_0515sum','aps_APSDTRCOD_night_00_06_data0414_0515nunique','aps_qz_APSDTRCOD_two_night_00_06_data0414_0515count','aps_qz_APSDTRCOD_two_night_00_06_data0515_0615count','mbank_qrytrnflw_TFT_STDBSNCOD_night_00_06_data0515_0615nunique','mbank_qrytrnflw_TFT_STDBSNCOD_max_night_00_06_data0515_0615count','mbank_qrytrnflw_TFT_STDBSNCOD_two_night_00_06_data0414_0515count','mbank_qrytrnflw_TFT_STDBSNCOD_three_night_00_06_data0515_0615count','aps_night_00_06_data0414_0421nunique','aps_night_00_06_data0421_0428nunique','aps_night_00_06_data0428_0505nunique','aps_night_00_06_data0512_0519nunique','aps_night_00_06_data0428_0505sum','aps_night_00_06_data0505_0512sum','aps_money_S0_night_00_06_data0519_0526sum','aps_APSDTRCOD_night_00_06_data0421_0428nunique','aps_APSDTRCOD_night_00_06_data0519_0526nunique','aps_qz_APSDTRCOD_two_night_00_06_data0505_0512count','aps_qz_APSDTRCOD_two_night_00_06_data0519_0526count','aps_qz_APSDTRCHL_two_night_00_06_data0519_0526count','aps_money_B0_night_06_18_data0515_0615sum','aps_money_S0_night_06_18_data0515_0615sum','aps_qz_APSDTRCHL_three_night_06_18_data0515_0615count','mbank_trnflw_TFT_TRNAMT_night_06_18_data0515_0615sum','aps_night_06_18_data0505_0512nunique','aps_night_06_18_data0512_0519nunique','aps_night_06_18_data0428_0505sum','aps_money_B0_night_06_18_data0602_0609sum','aps_money_S0_night_06_18_data0526_0602sum','aps_money_S0_night_06_18_data0602_0609sum','aps_qz_APSDTRCOD_two_night_06_18_data0505_0512count','aps_qz_APSDTRCHL_max_night_06_18_data0602_0609count','mbank_trnflw_TFT_CRPACC_night_06_18_data0602_0609nunique','mbank_trnflw_TFT_STDBSNCOD_max_night_06_18_data0602_0609count','mbank_qrytrnflw_TFT_STDBSNCOD_night_06_18_data0414_0421nunique','mbank_qrytrnflw_TFT_STDBSNCOD_night_06_18_data0526_0602nunique','mbank_qrytrnflw_TFT_STDBSNCOD_max_night_06_18_data0519_0526count','mbank_qrytrnflw_TFT_STDBSNCOD_max_night_06_18_data0526_0602count','mbank_qrytrnflw_TFT_STDBSNCOD_max_night_06_18_data0602_0609count','mbank_trnflw_TFT_STDBSNCOD_max_night_18_06_data0515_0615count','mbank_qrytrnflw_TFT_STDBSNCOD_night_18_06_data0515_0615nunique','mbank_qrytrnflw_TFT_STDBSNCOD_max_night_18_06_data0414_0515count','mbank_qrytrnflw_TFT_STDBSNCOD_max_night_18_06_data0515_0615count','mbank_qrytrnflw_TFT_STDBSNCOD_two_night_18_06_data0515_0615count','aps_night_18_06_data0414_0421sum','aps_money_B0_night_18_06_data0505_0512sum','aps_money_S0_night_18_06_data0505_0512sum','aps_money_S0_night_18_06_data0519_0526sum','aps_APSDTRCOD_night_18_06_data0519_0526nunique','aps_qz_APSDTRCOD_max_night_18_06_data0428_0505count','aps_qz_APSDTRCOD_max_night_18_06_data0519_0526count','aps_qz_APSDTRCOD_max_night_18_06_data0526_0602count','aps_qz_APSDTRCOD_max_night_18_06_data0602_0609count','aps_qz_APSDTRCOD_two_night_18_06_data0505_0512count','aps_qz_APSDTRCHL_max_night_18_06_data0428_0505count','aps_qz_APSDTRCHL_max_night_18_06_data0526_0602count','aps_qz_APSDTRCHL_max_night_18_06_data0602_0609count','aps_qz_APSDTRCHL_three_night_18_06_data0602_0609count','mbank_trnflw_TFT_STDBSNCOD_night_18_06_data0602_0609nunique','mbank_trnflw_TFT_TRNAMT_night_18_06_data0414_0421sum','mbank_trnflw_TFT_CRPACC_night_18_06_data0526_0602nunique','mbank_trnflw_TFT_STDBSNCOD_max_night_18_06_data0421_0428count','mbank_qrytrnflw_TFT_STDBSNCOD_max_night_18_06_data0505_0512count','mbank_qrytrnflw_TFT_STDBSNCOD_two_night_18_06_data0414_0421count','mbank_qrytrnflw_TFT_STDBSNCOD_two_night_18_06_data0421_0428count','mbank_qrytrnflw_TFT_STDBSNCOD_three_night_18_06_data0512_0519count','mbank_qrytrnflw_TFT_STDBSNCOD_three_night_18_06_data0526_0602count']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-11-07T06:23:18.992653Z",
     "iopub.status.busy": "2023-11-07T06:23:18.992479Z",
     "iopub.status.idle": "2023-11-07T06:23:18.995451Z",
     "shell.execute_reply": "2023-11-07T06:23:18.994940Z",
     "shell.execute_reply.started": "2023-11-07T06:23:18.992631Z"
    },
    "jupyter": {
     "source_hidden": true
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "# # # 筛选重复列\n",
    "# # reapt_col = []\n",
    "# # for col1 in dataset.columns:\n",
    "# #     times = 0\n",
    "# #     for col2 in dataset.columns:\n",
    "# #         if col1 == col2: times += 1\n",
    "# #     if times > 1 : reapt_col.append(col1)\n",
    "\n",
    "\n",
    "# # 训练集\n",
    "# train_df = dataset[~dataset['FLAG'].isnull()].reset_index(drop=True)\n",
    "# # 测试集\n",
    "# test_df = dataset[dataset['FLAG'].isnull()]\n",
    "\n",
    "\n",
    "# #dataset = dataset.drop('times_mean_x',axis=1)\n",
    "# # 筛选特征\n",
    "# unique_1_cols = []\n",
    "# # for col in [col for col in dataset.columns if 'list' not in col]:\n",
    "# for col in [col for col in dataset.columns]:\n",
    "# #     print(col)\n",
    "#     if train_df[col].nunique() < 2:\n",
    "#         unique_1_cols.append(col)\n",
    "# print(unique_1_cols)\n",
    "\n",
    "# # 空值率高\n",
    "# null_percentage = dataset.isnull().mean()\n",
    "# threshold = 0.98\n",
    "# null_high_col = []\n",
    "# null_high_col = null_percentage[null_percentage>threshold].index.tolist()\n",
    "\n",
    "# # 预删除特征 \n",
    "# drop_cols = ['DATA_DAT','CARD_NO','CUST_NO', 'FLAG']\n",
    "# time_cols = []\n",
    "# feature_name = [i for i in train_df.columns if i not in drop_cols+unique_1_cols+time_cols+null_high_col]\n",
    "\n",
    "# print(len(feature_name))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-11-07T06:23:18.996398Z",
     "iopub.status.busy": "2023-11-07T06:23:18.996230Z",
     "iopub.status.idle": "2023-11-07T06:23:18.998629Z",
     "shell.execute_reply": "2023-11-07T06:23:18.998152Z",
     "shell.execute_reply.started": "2023-11-07T06:23:18.996378Z"
    },
    "jupyter": {
     "source_hidden": true
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "# import pickle\n",
    "\n",
    "\n",
    "# CSTLOGQUERY_feature_file_name = \"bak/feature_name_0625_cat.pkl\"\n",
    "\n",
    "\n",
    "\n",
    "# # 使用pickle.dump()将特征矩阵保存为二进制文件\n",
    "# with open(CSTLOGQUERY_feature_file_name, 'wb') as file:\n",
    "#     pickle.dump(feature_name, file)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-11-07T06:23:18.999613Z",
     "iopub.status.busy": "2023-11-07T06:23:18.999436Z",
     "iopub.status.idle": "2023-11-07T06:23:19.003739Z",
     "shell.execute_reply": "2023-11-07T06:23:19.003238Z",
     "shell.execute_reply.started": "2023-11-07T06:23:18.999592Z"
    },
    "jupyter": {
     "source_hidden": true
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "# # 训练集\n",
    "# train_df = dataset[~dataset['FLAG'].isnull()].reset_index(drop=True)\n",
    "# # 测试集\n",
    "# test_df = dataset[dataset['FLAG'].isnull()]\n",
    "\n",
    "# # 生成训练集\n",
    "# X_train = train_df.copy()\n",
    "# y = X_train['FLAG']\n",
    "# X_train = X_train[feature_name]\n",
    "\n",
    "# print('X_train.shape:', X_train.shape)\n",
    "# #指定非数值列 便于使用Catboost编码\n",
    "# categorical_features_indices = np.where(X_train.dtypes != np.float)[0]\n",
    "# # categorical_features_indices = []\n",
    "\n",
    "# def xuanze(used_feat,df_train,ycol,mode,categorical_features_indices,seed):\n",
    "#     seed = 2020\n",
    "\n",
    "#     #model = XGBClassifier(boosting_type='gbdt',num_leaves=15,max_depth=6,learning_rate=0.01,n_estimators=2000,subsample=0.8,tree_method = 'gpu_hist',\n",
    "#     #                       feature_fraction=0.7,random_state=seed,is_unbalance=True,eval_metric='auc')\n",
    "# #         model = LGBMClassifier(objective='binary',boosting_type='gbdt',num_leaves=34,max_depth=15,learning_rate=0.01,n_estimators=2000,subsample=0.8,\n",
    "# #                             feature_fraction=0.7,reg_alpha=10,reg_lambda= 12,random_state=seed,is_unbalance=True,\n",
    "# #                             #metric='auc',\n",
    "# #                             n_jobs=8,bagging_freq=1)\n",
    "\n",
    "#     model = CatBoostClassifier(\n",
    "#         loss_function = \"Logloss\",\n",
    "#         eval_metric = \"AUC\",\n",
    "#     #    custom_metric=[CustomF2Metric()],\n",
    "#     #    auto_class_weights = 'Balanced',\n",
    "#         learning_rate = 0.05,\n",
    "#         iterations = 1000,\n",
    "#         random_seed = 42,\n",
    "#         verbose = 100,\n",
    "#         early_stopping_rounds = 200,\n",
    "#         depth = 3,\n",
    "# #        reg_lambda = 2\n",
    "#     )\n",
    "\n",
    "#     X_train = df_train[used_feat]\n",
    "#     if mode == True:\n",
    "#         Y_train = df_train[ycol]\n",
    "#     else:\n",
    "#         Y_train = df_train[ycol].copy().sample(frac=1.0,random_state = seed)\n",
    "\n",
    "\n",
    "# #     lgb_model = model.fit(X_train,\n",
    "# #                         Y_train,\n",
    "# #                         #eval_names=['train', 'valid'],\n",
    "# #                         eval_set=[(X_train, Y_train)],\n",
    "# #                         verbose=100,\n",
    "# #                         #categorical_feature = ['catory'],\n",
    "# #                         #early_stopping_rounds=200\n",
    "# #                         )\n",
    "\n",
    "#     train_pool = Pool(X_train,Y_train,cat_features = categorical_features_indices)\n",
    "# #    validate_pool = Pool(test_x,test_y,cat_features = categorical_features_indices)\n",
    "#     cat_model = model.fit(\n",
    "#         train_pool,\n",
    "#         eval_set=train_pool,\n",
    "#         plot = False\n",
    "#     )\n",
    "# #     df_plot_importance = pd.DataFrame() \n",
    "# #     df_plot_importance['feature name'] = feature_name\n",
    "# #     df_plot_importance['importance'] = cat_model.get_feature_importance()\n",
    "# #     df_plot_importance = df_plot_importance.sort_values('importance',ascending=False) \n",
    "# #     #df_plot_importance.plot.barh(x = 'feature name',figsize=(15,80),fontsize=10)\n",
    "# #     df_plot_importance.head(20)\n",
    "\n",
    "#     df_importance = pd.DataFrame({\n",
    "#         'column': used_feat,\n",
    "#         'importance': cat_model.get_feature_importance(),\n",
    "#     })\n",
    "\n",
    "#     return df_importance\n",
    "\n",
    "# imp1 = xuanze(feature_name,train_df,'FLAG',True,categorical_features_indices,12)\n",
    "# imp2 = xuanze(feature_name,train_df,'FLAG',False,categorical_features_indices,123)\n",
    "# imp3 = xuanze(feature_name,train_df,'FLAG',False,categorical_features_indices,987)\n",
    "# imp4 = xuanze(feature_name,train_df,'FLAG',False,categorical_features_indices,6596)\n",
    "# imp5 = xuanze(feature_name,train_df,'FLAG',False,categorical_features_indices,8)\n",
    "# imp6 = xuanze(feature_name,train_df,'FLAG',False,categorical_features_indices,635894)\n",
    "# imp7 = xuanze(feature_name,train_df,'FLAG',False,categorical_features_indices,335)\n",
    "# imp8 = xuanze(feature_name,train_df,'FLAG',False,categorical_features_indices,9365)\n",
    "# imp9 = xuanze(feature_name,train_df,'FLAG',False,categorical_features_indices,3542)\n",
    "# imp10 = xuanze(feature_name,train_df,'FLAG',False,categorical_features_indices,356)\n",
    "# imp11 = xuanze(feature_name,train_df,'FLAG',False,categorical_features_indices,3654)\n",
    "\n",
    "# imp1.columns =  ['column','importance_1']\n",
    "# imp2.columns =  ['column','importance_2']\n",
    "# imp3.columns =  ['column','importance_3']\n",
    "# imp4.columns =  ['column','importance_4']\n",
    "# imp5.columns =  ['column','importance_5']\n",
    "# imp6.columns =  ['column','importance_6']\n",
    "# imp7.columns =  ['column','importance_7']\n",
    "# imp8.columns =  ['column','importance_8']\n",
    "# imp9.columns =  ['column','importance_9']\n",
    "# imp10.columns =  ['column','importance_10']\n",
    "# imp11.columns =  ['column','importance_11']\n",
    "\n",
    "# imp = pd.merge(imp1,imp2,on = ['column'],how = 'left')\n",
    "# imp = pd.merge(imp,imp3,on = ['column'],how = 'left')\n",
    "# imp = pd.merge(imp,imp4,on = ['column'],how = 'left')\n",
    "# imp = pd.merge(imp,imp5,on = ['column'],how = 'left')\n",
    "# imp = pd.merge(imp,imp6,on = ['column'],how = 'left')\n",
    "# imp = pd.merge(imp,imp7,on = ['column'],how = 'left')\n",
    "# imp = pd.merge(imp,imp8,on = ['column'],how = 'left')\n",
    "# imp = pd.merge(imp,imp9,on = ['column'],how = 'left')\n",
    "# imp = pd.merge(imp,imp10,on = ['column'],how = 'left')\n",
    "# imp = pd.merge(imp,imp11,on = ['column'],how = 'left')\n",
    "# fea = ['importance_{}'.format(i) for i in range(2,12)]\n",
    "# imp['mean'] = imp[fea].mean(axis = 1)\n",
    "# used_feat1 = imp.loc[imp['importance_1']>imp['mean']]['column'].values\n",
    "\n",
    "# # xuanze(feature_name,train_df,'FLAG', )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-11-07T06:23:19.004638Z",
     "iopub.status.busy": "2023-11-07T06:23:19.004469Z",
     "iopub.status.idle": "2023-11-07T06:23:19.006844Z",
     "shell.execute_reply": "2023-11-07T06:23:19.006355Z",
     "shell.execute_reply.started": "2023-11-07T06:23:19.004617Z"
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "# len(used_feat1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-11-07T06:23:19.008528Z",
     "iopub.status.busy": "2023-11-07T06:23:19.008362Z",
     "iopub.status.idle": "2023-11-07T06:23:19.010707Z",
     "shell.execute_reply": "2023-11-07T06:23:19.010208Z",
     "shell.execute_reply.started": "2023-11-07T06:23:19.008508Z"
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "# feature_name= used_feat1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-11-07T06:23:19.011888Z",
     "iopub.status.busy": "2023-11-07T06:23:19.011727Z",
     "iopub.status.idle": "2023-11-07T06:23:19.018001Z",
     "shell.execute_reply": "2023-11-07T06:23:19.017476Z",
     "shell.execute_reply.started": "2023-11-07T06:23:19.011868Z"
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "\n",
    "\n",
    "def f_score(y_true, y_pred):\n",
    "\n",
    "    precisions, recalls, thresholds = precision_recall_curve(y_true, y_pred)\n",
    "\n",
    "    # F1\n",
    "#     f1_scores = (2 * precisions * recalls) / (precisions + recalls)\n",
    "#     best_t = thresholds[np.argmax(f1_scores[np.isfinite(f1_scores)])]\n",
    "#     y_1 = [1 if x >= best_t else 0 for x in y_pred]\n",
    "#     recall = recall_score(y_true, y_1)\n",
    "#     precision = precision_score(y_true, y_1)\n",
    "#     F_score = f1_score(y_true, y_1)\n",
    "#     F_score = (2 * precision * recall) / (precision + recall)\n",
    "\n",
    "    # F2\n",
    "    f2_scores = (5 * precisions * recalls) / (4*precisions + recalls)\n",
    "    best_t = thresholds[np.argmax(f2_scores[np.isfinite(f2_scores)])]\n",
    "    y_1 = [1 if x >= best_t else 0 for x in y_pred]\n",
    "    recall = recall_score(y_true, y_1)\n",
    "    precision = precision_score(y_true, y_1)\n",
    "    F_score = (5 * precision * recall) / (4*precision + recall)\n",
    "\n",
    "    #print(f\"valid's f1: {F_score}\")\n",
    "    print(\"最佳阈值: \", str(best_t))\n",
    "    print('打印分类报告')\n",
    "    clf_report1 = classification_report(y_true.values, y_1)\n",
    "    print(clf_report1)\n",
    "\n",
    "    return F_score, recall, precision, best_t"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-11-07T06:23:19.018984Z",
     "iopub.status.busy": "2023-11-07T06:23:19.018806Z",
     "iopub.status.idle": "2023-11-07T06:23:19.021278Z",
     "shell.execute_reply": "2023-11-07T06:23:19.020788Z",
     "shell.execute_reply.started": "2023-11-07T06:23:19.018963Z"
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "# # 训练集\n",
    "# train_df = dataset[~dataset['FLAG'].isnull()].reset_index(drop=True)\n",
    "# # 测试集\n",
    "# test_df = dataset[dataset['FLAG'].isnull()]\n",
    "\n",
    "# # 欠采样\n",
    "# from imblearn.under_sampling import RandomUnderSampler\n",
    "\n",
    "# NUM_POS = dataset.FLAG.sum().astype(int)\n",
    "# sampler = RandomUnderSampler(sampling_strategy = {0:NUM_POS, 1:NUM_POS})\n",
    "\n",
    "# train_df,y = sampler.fit_resample(train_df[feature_name], train_df['FLAG'].astype(int))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-11-07T06:23:19.022109Z",
     "iopub.status.busy": "2023-11-07T06:23:19.021945Z",
     "iopub.status.idle": "2023-11-07T06:24:50.969517Z",
     "shell.execute_reply": "2023-11-07T06:24:50.968710Z",
     "shell.execute_reply.started": "2023-11-07T06:23:19.022090Z"
    },
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "X_train.shape: (37050, 767)\n",
      "0:\ttest: 0.7477126\tbest: 0.7477126 (0)\ttotal: 65.2ms\tremaining: 1m 5s\n",
      "100:\ttest: 0.9203046\tbest: 0.9203046 (100)\ttotal: 1.13s\tremaining: 10.1s\n",
      "200:\ttest: 0.9302528\tbest: 0.9302528 (200)\ttotal: 2.17s\tremaining: 8.64s\n",
      "300:\ttest: 0.9336836\tbest: 0.9337052 (298)\ttotal: 3.22s\tremaining: 7.47s\n",
      "400:\ttest: 0.9357572\tbest: 0.9357842 (392)\ttotal: 4.25s\tremaining: 6.35s\n",
      "500:\ttest: 0.9373870\tbest: 0.9373870 (500)\ttotal: 5.27s\tremaining: 5.25s\n",
      "600:\ttest: 0.9386310\tbest: 0.9387665 (594)\ttotal: 6.3s\tremaining: 4.18s\n",
      "700:\ttest: 0.9392384\tbest: 0.9393100 (699)\ttotal: 7.32s\tremaining: 3.12s\n",
      "800:\ttest: 0.9403065\tbest: 0.9403065 (800)\ttotal: 8.35s\tremaining: 2.07s\n",
      "900:\ttest: 0.9407963\tbest: 0.9408138 (894)\ttotal: 9.39s\tremaining: 1.03s\n",
      "999:\ttest: 0.9412579\tbest: 0.9412762 (997)\ttotal: 10.4s\tremaining: 0us\n",
      "\n",
      "bestTest = 0.9412762072\n",
      "bestIteration = 997\n",
      "\n",
      "Shrink model to first 998 iterations.\n",
      "ks值： 0.7376068376068377\n",
      "最佳阈值:  0.11742403925559361\n",
      "打印分类报告\n",
      "              precision    recall  f1-score   support\n",
      "\n",
      "         0.0       0.99      0.95      0.97      7020\n",
      "         1.0       0.46      0.74      0.57       390\n",
      "\n",
      "    accuracy                           0.94      7410\n",
      "   macro avg       0.72      0.85      0.77      7410\n",
      "weighted avg       0.96      0.94      0.95      7410\n",
      "\n",
      "f2_score: (0.6614963503649636, 0.7435897435897436, 0.4588607594936709, 0.11742403925559361)\n",
      "0:\ttest: 0.7371448\tbest: 0.7371448 (0)\ttotal: 12.7ms\tremaining: 12.6s\n",
      "100:\ttest: 0.9244430\tbest: 0.9244430 (100)\ttotal: 1.08s\tremaining: 9.61s\n",
      "200:\ttest: 0.9316192\tbest: 0.9316199 (199)\ttotal: 2.12s\tremaining: 8.43s\n",
      "300:\ttest: 0.9347907\tbest: 0.9348302 (297)\ttotal: 3.16s\tremaining: 7.33s\n",
      "400:\ttest: 0.9370820\tbest: 0.9370820 (400)\ttotal: 4.21s\tremaining: 6.29s\n",
      "500:\ttest: 0.9383673\tbest: 0.9384093 (497)\ttotal: 5.24s\tremaining: 5.22s\n",
      "600:\ttest: 0.9389488\tbest: 0.9390836 (597)\ttotal: 6.3s\tremaining: 4.18s\n",
      "700:\ttest: 0.9400741\tbest: 0.9400825 (692)\ttotal: 7.34s\tremaining: 3.13s\n",
      "800:\ttest: 0.9404847\tbest: 0.9405139 (789)\ttotal: 8.38s\tremaining: 2.08s\n",
      "900:\ttest: 0.9410333\tbest: 0.9411104 (891)\ttotal: 9.42s\tremaining: 1.03s\n",
      "999:\ttest: 0.9414957\tbest: 0.9414990 (998)\ttotal: 10.4s\tremaining: 0us\n",
      "\n",
      "bestTest = 0.9414990138\n",
      "bestIteration = 998\n",
      "\n",
      "Shrink model to first 999 iterations.\n",
      "ks值： 0.7410256410256411\n",
      "最佳阈值:  0.10052961581365927\n",
      "打印分类报告\n",
      "              precision    recall  f1-score   support\n",
      "\n",
      "         0.0       0.99      0.95      0.97      7020\n",
      "         1.0       0.44      0.76      0.56       390\n",
      "\n",
      "    accuracy                           0.94      7410\n",
      "   macro avg       0.72      0.85      0.76      7410\n",
      "weighted avg       0.96      0.94      0.94      7410\n",
      "\n",
      "f2_score: (0.6635177687809267, 0.7564102564102564, 0.444947209653092, 0.10052961581365927)\n",
      "0:\ttest: 0.7231863\tbest: 0.7231863 (0)\ttotal: 13ms\tremaining: 13s\n",
      "100:\ttest: 0.9275429\tbest: 0.9275429 (100)\ttotal: 1.09s\tremaining: 9.72s\n",
      "200:\ttest: 0.9343444\tbest: 0.9343940 (199)\ttotal: 2.16s\tremaining: 8.57s\n",
      "300:\ttest: 0.9369260\tbest: 0.9369260 (299)\ttotal: 3.18s\tremaining: 7.39s\n",
      "400:\ttest: 0.9389426\tbest: 0.9389426 (400)\ttotal: 4.22s\tremaining: 6.3s\n",
      "500:\ttest: 0.9396837\tbest: 0.9396837 (500)\ttotal: 6.08s\tremaining: 6.06s\n",
      "600:\ttest: 0.9407561\tbest: 0.9407700 (578)\ttotal: 8.05s\tremaining: 5.35s\n",
      "700:\ttest: 0.9419315\tbest: 0.9419315 (700)\ttotal: 10.2s\tremaining: 4.33s\n",
      "800:\ttest: 0.9428380\tbest: 0.9428380 (800)\ttotal: 12.2s\tremaining: 3.04s\n",
      "900:\ttest: 0.9435795\tbest: 0.9435795 (900)\ttotal: 14.2s\tremaining: 1.56s\n",
      "999:\ttest: 0.9443385\tbest: 0.9443612 (996)\ttotal: 16.2s\tremaining: 0us\n",
      "\n",
      "bestTest = 0.9443611659\n",
      "bestIteration = 996\n",
      "\n",
      "Shrink model to first 997 iterations.\n",
      "ks值： 0.7565527065527066\n",
      "最佳阈值:  0.09583960188759237\n",
      "打印分类报告\n",
      "              precision    recall  f1-score   support\n",
      "\n",
      "         0.0       0.99      0.95      0.97      7020\n",
      "         1.0       0.47      0.78      0.58       390\n",
      "\n",
      "    accuracy                           0.94      7410\n",
      "   macro avg       0.73      0.86      0.78      7410\n",
      "weighted avg       0.96      0.94      0.95      7410\n",
      "\n",
      "f2_score: (0.6861413043478262, 0.7769230769230769, 0.4675925925925926, 0.09583960188759237)\n",
      "0:\ttest: 0.7206480\tbest: 0.7206480 (0)\ttotal: 13.8ms\tremaining: 13.8s\n",
      "100:\ttest: 0.9228479\tbest: 0.9228548 (99)\ttotal: 2.16s\tremaining: 19.2s\n",
      "200:\ttest: 0.9301231\tbest: 0.9301231 (200)\ttotal: 4.26s\tremaining: 16.9s\n",
      "300:\ttest: 0.9331697\tbest: 0.9331697 (300)\ttotal: 6.24s\tremaining: 14.5s\n",
      "400:\ttest: 0.9355395\tbest: 0.9355395 (400)\ttotal: 8.24s\tremaining: 12.3s\n",
      "500:\ttest: 0.9369698\tbest: 0.9369698 (500)\ttotal: 10.3s\tremaining: 10.2s\n",
      "600:\ttest: 0.9380262\tbest: 0.9380313 (599)\ttotal: 12.3s\tremaining: 8.13s\n",
      "700:\ttest: 0.9392165\tbest: 0.9392165 (700)\ttotal: 14.3s\tremaining: 6.11s\n",
      "800:\ttest: 0.9401640\tbest: 0.9401834 (795)\ttotal: 16.3s\tremaining: 4.06s\n",
      "900:\ttest: 0.9409500\tbest: 0.9409533 (899)\ttotal: 18.4s\tremaining: 2.02s\n",
      "999:\ttest: 0.9418566\tbest: 0.9418723 (992)\ttotal: 20.3s\tremaining: 0us\n",
      "\n",
      "bestTest = 0.9418723062\n",
      "bestIteration = 992\n",
      "\n",
      "Shrink model to first 993 iterations.\n",
      "ks值： 0.7505698005698005\n",
      "最佳阈值:  0.1300273474517733\n",
      "打印分类报告\n",
      "              precision    recall  f1-score   support\n",
      "\n",
      "         0.0       0.99      0.96      0.97      7020\n",
      "         1.0       0.51      0.76      0.61       390\n",
      "\n",
      "    accuracy                           0.95      7410\n",
      "   macro avg       0.75      0.86      0.79      7410\n",
      "weighted avg       0.96      0.95      0.95      7410\n",
      "\n",
      "f2_score: (0.6912657636618403, 0.7589743589743589, 0.5094664371772806, 0.1300273474517733)\n",
      "0:\ttest: 0.7189377\tbest: 0.7189377 (0)\ttotal: 13.8ms\tremaining: 13.8s\n",
      "100:\ttest: 0.9239009\tbest: 0.9239433 (99)\ttotal: 2.08s\tremaining: 18.5s\n",
      "200:\ttest: 0.9306494\tbest: 0.9306805 (198)\ttotal: 4.16s\tremaining: 16.5s\n",
      "300:\ttest: 0.9327047\tbest: 0.9327047 (300)\ttotal: 6.14s\tremaining: 14.3s\n",
      "400:\ttest: 0.9345332\tbest: 0.9345332 (400)\ttotal: 8.13s\tremaining: 12.1s\n",
      "500:\ttest: 0.9358280\tbest: 0.9358280 (500)\ttotal: 10.2s\tremaining: 10.1s\n",
      "600:\ttest: 0.9373807\tbest: 0.9373807 (600)\ttotal: 12.1s\tremaining: 8.04s\n",
      "700:\ttest: 0.9385941\tbest: 0.9386003 (697)\ttotal: 14.2s\tremaining: 6.06s\n",
      "800:\ttest: 0.9399562\tbest: 0.9399562 (800)\ttotal: 16.4s\tremaining: 4.08s\n",
      "900:\ttest: 0.9411071\tbest: 0.9411071 (900)\ttotal: 18.3s\tremaining: 2.01s\n",
      "999:\ttest: 0.9415509\tbest: 0.9415794 (988)\ttotal: 19.9s\tremaining: 0us\n",
      "\n",
      "bestTest = 0.9415793703\n",
      "bestIteration = 988\n",
      "\n",
      "Shrink model to first 989 iterations.\n",
      "ks值： 0.7417378917378917\n",
      "最佳阈值:  0.12410690155561159\n",
      "打印分类报告\n",
      "              precision    recall  f1-score   support\n",
      "\n",
      "         0.0       0.99      0.95      0.97      7020\n",
      "         1.0       0.48      0.75      0.58       390\n",
      "\n",
      "    accuracy                           0.94      7410\n",
      "   macro avg       0.73      0.85      0.78      7410\n",
      "weighted avg       0.96      0.94      0.95      7410\n",
      "\n",
      "f2_score: (0.6728110599078341, 0.7487179487179487, 0.4786885245901639, 0.12410690155561159)\n"
     ]
    }
   ],
   "source": [
    "# 训练集\n",
    "train_df = dataset[~dataset['FLAG'].isnull()].reset_index(drop=True)\n",
    "# 测试集\n",
    "test_df = dataset[dataset['FLAG'].isnull()]\n",
    "\n",
    "from sklearn.metrics import roc_curve, auc\n",
    "splits = 5\n",
    "skf = StratifiedKFold(n_splits = splits, random_state=1996, shuffle=True)\n",
    "\n",
    "model = CatBoostClassifier(\n",
    "    loss_function = \"Logloss\",\n",
    "    eval_metric = \"AUC\",\n",
    "#    custom_metric=[CustomF2Metric()],\n",
    "#    auto_class_weights = 'Balanced',\n",
    "    learning_rate = 0.05,\n",
    "    iterations = 1000,\n",
    "    random_seed = 42,\n",
    "    verbose = 100,\n",
    "    early_stopping_rounds = 200,\n",
    "    depth = 3,\n",
    "#     reg_lambda = 2\n",
    ")\n",
    "# 生成训练集\n",
    "X_train = train_df.copy()\n",
    "y = X_train['FLAG']\n",
    "X_train = X_train[feature_name]\n",
    "\n",
    "print('X_train.shape:', X_train.shape)\n",
    "#指定非数值列 便于使用Catboost编码\n",
    "categorical_features_indices = np.where(X_train.dtypes != np.float)[0]\n",
    "# categorical_features_indices = []\n",
    "\n",
    "# 生成测试集\n",
    "df_test = test_df\n",
    "X_test = df_test.copy()\n",
    "X_test=X_test[feature_name]\n",
    "\n",
    "oof = np.zeros(X_train.shape[0])\n",
    "prediction = np.zeros(X_test.shape[0])\n",
    "    \n",
    "for index, (train_index, test_index) in enumerate(skf.split(X_train, y)):\n",
    "    train_x, test_x, train_y, test_y = X_train.iloc[train_index], X_train.iloc[test_index], y.iloc[train_index], y.iloc[test_index]\n",
    "    train_pool = Pool(train_x,train_y,cat_features = categorical_features_indices)\n",
    "    validate_pool = Pool(test_x,test_y,cat_features = categorical_features_indices)\n",
    "    cat_model = model.fit(\n",
    "        train_pool,\n",
    "        eval_set=validate_pool,\n",
    "        plot = False\n",
    "    )\n",
    "    \n",
    "    x2 = cat_model.predict(test_x,prediction_type = \"Probability\")[:,-1]\n",
    "    fpr,tpr,threshold =roc_curve(test_y,x2)\n",
    "    print(\"ks值：\",max(tpr-fpr))\n",
    "    prediction += cat_model.predict(X_test,prediction_type = \"Probability\")[:,-1] / splits\n",
    "    print(\"f2_score:\",f_score(test_y,x2))\n",
    "    oof[test_index] += x2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-11-07T06:24:50.970795Z",
     "iopub.status.busy": "2023-11-07T06:24:50.970586Z",
     "iopub.status.idle": "2023-11-07T06:24:51.200661Z",
     "shell.execute_reply": "2023-11-07T06:24:51.199979Z",
     "shell.execute_reply.started": "2023-11-07T06:24:50.970771Z"
    },
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "最佳阈值:  0.0968865219436811\n",
      "打印分类报告\n",
      "              precision    recall  f1-score   support\n",
      "\n",
      "         0.0       0.99      0.94      0.97     35100\n",
      "         1.0       0.44      0.77      0.56      1950\n",
      "\n",
      "    accuracy                           0.94     37050\n",
      "   macro avg       0.71      0.86      0.76     37050\n",
      "weighted avg       0.96      0.94      0.94     37050\n",
      "\n",
      "0.6677336178536498 0.7702564102564102 0.4357412242529736 0.0968865219436811\n",
      "AUC: 0.9419974870333845\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "0.09303643724696356"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\n",
    "def convert_prob_to_class(probabilites, threshold = 0.5):\n",
    "    classes = [1 if prob>=threshold else 0 for prob in probabilites]\n",
    "    return classes\n",
    "\n",
    "# F_score, recall, precision, best_t\n",
    "F_score, recall, precision, best_t = f_score(y, oof) \n",
    "print(F_score, recall, precision, best_t)\n",
    "print('AUC:' ,roc_auc_score(y, oof))\n",
    "\n",
    "y_pred = convert_prob_to_class(oof, best_t)\n",
    "sum(y_pred)/len(y_pred)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-11-07T06:24:51.201865Z",
     "iopub.status.busy": "2023-11-07T06:24:51.201668Z",
     "iopub.status.idle": "2023-11-07T06:24:51.208611Z",
     "shell.execute_reply": "2023-11-07T06:24:51.207984Z",
     "shell.execute_reply.started": "2023-11-07T06:24:51.201843Z"
    },
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 的个数 568\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "0.11305732484076433"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "prediction_y = convert_prob_to_class(prediction, best_t)\n",
    "print('1 的个数',sum(prediction_y))\n",
    "sum(prediction_y)/len(prediction_y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-11-07T06:24:51.209688Z",
     "iopub.status.busy": "2023-11-07T06:24:51.209497Z",
     "iopub.status.idle": "2023-11-07T06:24:51.234565Z",
     "shell.execute_reply": "2023-11-07T06:24:51.233883Z",
     "shell.execute_reply.started": "2023-11-07T06:24:51.209665Z"
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>feature name</th>\n",
       "      <th>importance</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>358</th>\n",
       "      <td>DPFAPROD_SUM_linear</td>\n",
       "      <td>2.271337</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>633</th>\n",
       "      <td>aps_APSDPRDNO_date_months_to_now_strange_cpts_...</td>\n",
       "      <td>2.085220</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>312</th>\n",
       "      <td>YAVER_AUM_BAL</td>\n",
       "      <td>2.055022</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>400</th>\n",
       "      <td>time_diff_std_trnflw_last14</td>\n",
       "      <td>1.987063</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>192</th>\n",
       "      <td>APSDCPTPRDNO_nunique_aps_qz_3c6c4e45e982dc8024...</td>\n",
       "      <td>1.970159</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>169</th>\n",
       "      <td>hour_std_aps_qz_0e30a5a85d29c720619212ed0721f096</td>\n",
       "      <td>0.294463</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>396</th>\n",
       "      <td>time_diff_mean_trnflw_last14</td>\n",
       "      <td>0.290129</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>45</th>\n",
       "      <td>APSDTRAMT_std_aps_qz_1488b47add3c27be40af16a79...</td>\n",
       "      <td>0.285599</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>624</th>\n",
       "      <td>APSDPRDNO_date_weeks_to_now_APSDTRAMT_skew_6_net</td>\n",
       "      <td>0.281650</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>383</th>\n",
       "      <td>trnflw_mAMT_TFT_DTE_month_std</td>\n",
       "      <td>0.273611</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>100 rows × 2 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                                          feature name  importance\n",
       "358                                DPFAPROD_SUM_linear    2.271337\n",
       "633  aps_APSDPRDNO_date_months_to_now_strange_cpts_...    2.085220\n",
       "312                                      YAVER_AUM_BAL    2.055022\n",
       "400                        time_diff_std_trnflw_last14    1.987063\n",
       "192  APSDCPTPRDNO_nunique_aps_qz_3c6c4e45e982dc8024...    1.970159\n",
       "..                                                 ...         ...\n",
       "169   hour_std_aps_qz_0e30a5a85d29c720619212ed0721f096    0.294463\n",
       "396                       time_diff_mean_trnflw_last14    0.290129\n",
       "45   APSDTRAMT_std_aps_qz_1488b47add3c27be40af16a79...    0.285599\n",
       "624   APSDPRDNO_date_weeks_to_now_APSDTRAMT_skew_6_net    0.281650\n",
       "383                      trnflw_mAMT_TFT_DTE_month_std    0.273611\n",
       "\n",
       "[100 rows x 2 columns]"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\n",
    "df_plot_importance = pd.DataFrame() \n",
    "df_plot_importance['feature name'] = feature_name\n",
    "df_plot_importance['importance'] = cat_model.get_feature_importance()\n",
    "df_plot_importance = df_plot_importance.sort_values('importance',ascending=False) \n",
    "#df_plot_importance.plot.barh(x = 'feature name',figsize=(15,80),fontsize=10)\n",
    "df_plot_importance.head(100)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-11-07T06:24:51.235766Z",
     "iopub.status.busy": "2023-11-07T06:24:51.235567Z",
     "iopub.status.idle": "2023-11-07T06:24:51.547138Z",
     "shell.execute_reply": "2023-11-07T06:24:51.546353Z",
     "shell.execute_reply.started": "2023-11-07T06:24:51.235742Z"
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "# 保存结果\n",
    "train_reslut = pd.read_csv( '../contest/train/TARGET_QZ.csv')\n",
    "#result_0902 = test_XW_AGET_PAY\n",
    "result_0902 = train_reslut\n",
    "result_0902['cat_oof'] = oof\n",
    "result_0902[['CUST_NO','FLAG','cat_oof']].to_csv('./tmp/TAcat_train_'+'_f2_{:.3f}'.format(F_score)+'.csv',index=False,header=0)\n",
    "#result_0902[['CONTNO',' ']].shape\n",
    "\n",
    "\n",
    "\n",
    "# 保存结果\n",
    "train_reslut = pd.read_csv( '../contest/A/TARGET_QZ_A.csv')\n",
    "#result_0902 = test_XW_AGET_PAY\n",
    "result_0902 = train_reslut\n",
    "result_0902['cat_prediction'] = prediction\n",
    "result_0902[['CUST_NO','cat_prediction']].to_csv('./tmp/TAcat_test_'+'_f2_{:.3f}'.format(F_score)+'.csv',index=False,header=0)\n",
    "#result_0902[['CONTNO',' ']].shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-11-07T06:24:51.548391Z",
     "iopub.status.busy": "2023-11-07T06:24:51.548183Z",
     "iopub.status.idle": "2023-11-07T06:24:51.551153Z",
     "shell.execute_reply": "2023-11-07T06:24:51.550546Z",
     "shell.execute_reply.started": "2023-11-07T06:24:51.548366Z"
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "# # 保存结果\n",
    "# test_XW_AGET_PAY = pd.read_csv( '../contest/A/TARGET_QZ_A.csv')\n",
    "# #result_0902 = test_XW_AGET_PAY\n",
    "# result_0902 = test_XW_AGET_PAY\n",
    "# result_0902['prediction_y'] = prediction_y\n",
    "# result_0902[['CUST_NO','prediction_y']].to_csv('../tmp/Tcat_'+str(sum(prediction_y))+'_f2_{:.3f}'.format(F_score)+'.csv',index=False,header=0)\n",
    "# #result_0902[['CONTNO',' ']].shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 融合"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-11-07T06:24:51.552149Z",
     "iopub.status.busy": "2023-11-07T06:24:51.551923Z",
     "iopub.status.idle": "2023-11-07T06:24:51.559250Z",
     "shell.execute_reply": "2023-11-07T06:24:51.558621Z",
     "shell.execute_reply.started": "2023-11-07T06:24:51.552116Z"
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "def f_score(y_true, y_pred):\n",
    "\n",
    "    precisions, recalls, thresholds = precision_recall_curve(y_true, y_pred)\n",
    "\n",
    "    # F2\n",
    "    f2_scores = (5 * precisions * recalls) / (4*precisions + recalls)\n",
    "    best_t = thresholds[np.argmax(f2_scores[np.isfinite(f2_scores)])]\n",
    "    y_1 = [1 if x >= best_t else 0 for x in y_pred]\n",
    "    recall = recall_score(y_true, y_1)\n",
    "    precision = precision_score(y_true, y_1)\n",
    "    F_score = (5 * precision * recall) / (4*precision + recall)\n",
    "    \n",
    "        #print(f\"valid's f1: {F_score}\")\n",
    "    print(\"最佳阈值: \", str(best_t))\n",
    "    print('打印分类报告')\n",
    "    clf_report1 = classification_report(y_true.values, y_1)\n",
    "    print(clf_report1)\n",
    "    \n",
    "    return F_score, recall, precision, best_t"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-11-07T06:24:51.560362Z",
     "iopub.status.busy": "2023-11-07T06:24:51.560175Z",
     "iopub.status.idle": "2023-11-07T06:24:51.676510Z",
     "shell.execute_reply": "2023-11-07T06:24:51.675680Z",
     "shell.execute_reply.started": "2023-11-07T06:24:51.560339Z"
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "\n",
    "\n",
    "cat_train = pd.read_csv('./tmp/TAcat_train__f2_0.668.csv',names = ['CUST_NO','FLAG','cat'])\n",
    "lgb_train = pd.read_csv('./tmp/A_lgb_train_oof.csv',names = ['CUST_NO','lgb'])\n",
    "# xgb_train = pd.read_csv('../share/xgb_train_pred_1026.csv',names = ['CUST_NO','xgb'])\n",
    "\n",
    "lgb_test = pd.read_csv('./tmp/A_lgb_test_prediction.csv',names = ['CUST_NO','lgb'])\n",
    "cat_test = pd.read_csv('./tmp/TAcat_test__f2_0.668.csv',names = ['CUST_NO','cat'])\n",
    "# xgb_test = pd.read_csv('../share/xgb_test_pred_1026.csv',names = ['CUST_NO','xgb'])\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-11-07T06:24:51.677776Z",
     "iopub.status.busy": "2023-11-07T06:24:51.677563Z",
     "iopub.status.idle": "2023-11-07T06:24:51.847146Z",
     "shell.execute_reply": "2023-11-07T06:24:51.846440Z",
     "shell.execute_reply.started": "2023-11-07T06:24:51.677751Z"
    },
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "最佳阈值:  0.0968865219436811\n",
      "打印分类报告\n",
      "              precision    recall  f1-score   support\n",
      "\n",
      "           0       0.99      0.94      0.97     35100\n",
      "           1       0.44      0.77      0.56      1950\n",
      "\n",
      "    accuracy                           0.94     37050\n",
      "   macro avg       0.71      0.86      0.76     37050\n",
      "weighted avg       0.96      0.94      0.94     37050\n",
      "\n",
      "0.6677336178536498 0.7702564102564102 0.4357412242529736 0.0968865219436811\n"
     ]
    }
   ],
   "source": [
    "F_score, recall, precision, best_t = f_score( cat_train['FLAG'], cat_train['cat'])\n",
    "print(F_score, recall, precision, best_t)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-11-07T06:24:51.848320Z",
     "iopub.status.busy": "2023-11-07T06:24:51.848115Z",
     "iopub.status.idle": "2023-11-07T06:24:51.902734Z",
     "shell.execute_reply": "2023-11-07T06:24:51.901970Z",
     "shell.execute_reply.started": "2023-11-07T06:24:51.848296Z"
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "fusion_train = lgb_train.merge(cat_train, on='CUST_NO', how = 'left')\n",
    "fusion_test = lgb_test.merge(cat_test, on='CUST_NO', how = 'left')\n",
    "\n",
    "fusion_train['fusion'] = 0.7*fusion_train['cat']+0.3*fusion_train['lgb']\n",
    "fusion_test['fusion'] = 0.7*fusion_test['cat']+0.3*fusion_test['lgb']\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-11-07T06:24:51.903960Z",
     "iopub.status.busy": "2023-11-07T06:24:51.903717Z",
     "iopub.status.idle": "2023-11-07T06:24:52.069846Z",
     "shell.execute_reply": "2023-11-07T06:24:52.069160Z",
     "shell.execute_reply.started": "2023-11-07T06:24:51.903935Z"
    },
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "最佳阈值:  0.14160491772162842\n",
      "打印分类报告\n",
      "              precision    recall  f1-score   support\n",
      "\n",
      "           0       0.98      0.96      0.97     35100\n",
      "           1       0.52      0.73      0.61      1950\n",
      "\n",
      "    accuracy                           0.95     37050\n",
      "   macro avg       0.75      0.85      0.79     37050\n",
      "weighted avg       0.96      0.95      0.95     37050\n",
      "\n",
      "0.6753936634414722 0.7302564102564103 0.5193289569657185 0.14160491772162842\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "0.07400809716599191"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "F_score, recall, precision, best_t = f_score( fusion_train['FLAG'], fusion_train['fusion'])\n",
    "print(F_score, recall, precision, best_t)\n",
    "\n",
    "sum(convert_prob_to_class(fusion_train['fusion'], best_t))/len(fusion_train)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-11-07T06:24:52.070897Z",
     "iopub.status.busy": "2023-11-07T06:24:52.070704Z",
     "iopub.status.idle": "2023-11-07T06:24:52.080164Z",
     "shell.execute_reply": "2023-11-07T06:24:52.079617Z",
     "shell.execute_reply.started": "2023-11-07T06:24:52.070873Z"
    },
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1个数 530\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "0.08837579617834394"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    " \n",
    "prediction_y = convert_prob_to_class(fusion_test['fusion'], 0.1082)\n",
    "print('1个数',sum(convert_prob_to_class(fusion_test['fusion'], 0.1082)))\n",
    "sum(convert_prob_to_class(fusion_test['fusion'], best_t))/len(fusion_test)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-11-07T06:24:52.082299Z",
     "iopub.status.busy": "2023-11-07T06:24:52.082112Z",
     "iopub.status.idle": "2023-11-07T06:24:52.114064Z",
     "shell.execute_reply": "2023-11-07T06:24:52.113364Z",
     "shell.execute_reply.started": "2023-11-07T06:24:52.082276Z"
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "# 保存结果\n",
    "test_XW_AGET_PAY = pd.read_csv( '../contest/A/TARGET_QZ_A.csv')\n",
    "#result_0902 = test_XW_AGET_PAY\n",
    "result_0902 = test_XW_AGET_PAY\n",
    "result_0902['prediction_y'] = prediction_y\n",
    "result_0902[['CUST_NO','prediction_y']].to_csv('./模型生成A榜答案_'+str(sum(prediction_y))+'_f2_{:.3f}'.format(F_score)+'.csv',index=False,header=0)\n",
    "#result_0902[['CONTNO',' ']].shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-11-07T06:24:52.115400Z",
     "iopub.status.busy": "2023-11-07T06:24:52.115208Z",
     "iopub.status.idle": "2023-11-07T06:24:52.208265Z",
     "shell.execute_reply": "2023-11-07T06:24:52.207493Z",
     "shell.execute_reply.started": "2023-11-07T06:24:52.115377Z"
    },
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Magic init complete.\n",
      "Predict init complete.\n",
      "Matplotlib env init complete.\n",
      "Gbase数据库信息配置为空，相关魔法命令不可使用（%sql, %df2db等），如有需求，请联系管理员配置或自行配置\n"
     ]
    }
   ],
   "source": [
    "init_woody"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-11-07T06:25:07.533725Z",
     "iopub.status.busy": "2023-11-07T06:25:07.533323Z",
     "iopub.status.idle": "2023-11-07T06:25:07.942551Z",
     "shell.execute_reply": "2023-11-07T06:25:07.942045Z",
     "shell.execute_reply.started": "2023-11-07T06:25:07.533683Z"
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'请稍后使用命令: %query_predict problem_id 查看评分结果, problem_id为阶段序号，取值为：1,2, 比如查询第一阶段的评分结果: %query_predict 1'"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%predict 3 ./模型生成A榜答案_530_f2_0.675.csv"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-11-07T06:25:09.186239Z",
     "iopub.status.busy": "2023-11-07T06:25:09.185943Z",
     "iopub.status.idle": "2023-11-07T06:25:09.475415Z",
     "shell.execute_reply": "2023-11-07T06:25:09.474789Z",
     "shell.execute_reply.started": "2023-11-07T06:25:09.186209Z"
    },
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "最近三次评分提交的结果供参考(大模型程序评分需要一些时间，请耐心等待，只有评分完成的结果会显示在下面的列表中):\n",
      "\n",
      "提交时间：2023-11-07 14:25:07 \t 评分结果：0.6516     \t 评分成功\n",
      "提交时间：2023-11-07 09:41:17 \t 评分结果：0.6516     \t 评分成功\n",
      "提交时间：2023-11-07 09:35:31 \t 评分结果：0.6516     \t 评分成功\n"
     ]
    }
   ],
   "source": [
    "%query_predict 3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
